Search

4.1 — Introduction to fundamental data types

Bits, bytes, and memory addressing

In lesson 1.3 -- Introduction to variables, we talked about the fact that variables are names for a piece of memory that can be used to store information. To recap briefly, computers have random access memory (RAM) that is available for programs to use. When a variable is defined, a piece of that memory is set aside for that variable.

The smallest unit of memory is a binary digit (also called a bit), which can hold a value of 0 or 1. You can think of a bit as being like a traditional light switch -- either the light is off (0), or it is on (1). There is no in-between. If you were to look at a random segment of memory, all you would see is …011010100101010… or some combination thereof.

Memory is organized into sequential units called memory addresses (or addresses for short). Similar to how a street address can be used to find a given house on a street, the memory address allows us to find and access the contents of memory at a particular location.

Perhaps surprisingly, in modern computer architectures, each bit does not get its own unique memory address. This is because the number of memory addresses are limited, and the need to access data bit-by-bit is rare. Instead, each memory address holds 1 byte of data. A byte is a group of bits that are operated on as a unit. The modern standard is that a byte is comprised of 8 sequential bits.

Key insight

In C++, we typically work with “byte-sized” chunks of data.

The following picture shows some sequential memory addresses, along with the corresponding byte of data:

Memory Addressing

As an aside...

Some older or non-standard machines may have bytes of a different size (from 1 to 48 bits) -- however, we generally need not worry about these, as the modern de-facto standard is that a byte is 8 bits. For these tutorials, we’ll assume a byte is 8 bits.

Data types

Because all data on a computer is just a sequence of bits, we use a data type (often called a “type” for short) to tell the compiler how to interpret the contents of memory in some meaningful way. You have already seen one example of a data type: the integer. When we declare a variable as an integer, we are telling the compiler “the piece of memory that this variable uses is going to be interpreted as a non-fractional number”.

When you assign a value to an object, the compiler and CPU take care of encoding your value into the appropriate sequence of bits for that data type. When you ask for your value back, your number is “reconstituted” from the sequence of bits in memory.

As an example, when you give an integer object the value 65, that value is stored in memory as the sequence of bits 0100 0001. When you need that value, those bits are reconstituted back into the integer value 65.

Fortunately, the compiler and CPU take care of converting values into bit sequences (and reconstructing those values from bit sequences again when needed), so you don’t need to worry about that part. All you need to do is pick a data type for your object that best matches your desired use.

Fundamental data types

C++ comes with built-in support for many different data types. These are called fundamental data types, but are often informally called basic types, primitive types, or built-in types.

Here is a list of the fundamental data types, some of which you have already seen:

Types Category Meaning Example
float
double
long double
Floating Point a number with a fractional part 3.14159
bool Integral (Boolean) true or false true
char
wchar_t
char8_t (C++20)
char16_t (C++11)
char32_t (C++11)
Integral (Character) a single character of text ‘c’
short
int
long
long long (C++11)
Integral (Integer) positive and negative whole numbers, including 0 64
std::nullptr_t (C++11) Null Pointer a null pointer nullptr
void Void no type n/a

This chapter is dedicated to exploring these fundamental data types in detail (except std::nullptr_t, which we’ll discuss when we talk about pointers). C++ also supports a number of other more complex types, called compound types. We’ll explore compound types in a future chapter.

Author's note

The terms “integer” and “integral” are similar, but have different meanings. Integers are positive and negative whole numbers, including 0. The term “integral types” (which means “like an integer”) includes all of the boolean, characters, and integer types (and thus is a bit broader in definition). Integral types are named so because they are stored in memory as integers, even though they behave slightly differently.

The _t suffix

Many of the types defined in newer versions of C++ (e.g. std::nullptr_t) use a _t suffix. This suffix means “type”, and it’s a common nomenclature applied to modern types.

If you see something with a _t suffix, it’s probably a type. But many types don’t have a _t suffix, so this isn’t consistently applied.


4.2 -- Void
Index
3.x -- Chapter 3 summary and quiz

74 comments to 4.1 — Introduction to fundamental data types

  • erjavinchanc

    ndia.This is because that there are plenty of dubious players that supply cheap automotive rental reservations only to provide you with a car this really is hardly suitable to meet your needs.The very low Car private coach rentals inside India own provided the opportunity for these types of elements for you to explore and also exploit this vulnerable users.So, tips on how to protect your household from finding caught in this messy state of affairs? The reply to this tough question lies in just an individual word -- 'diligence'.

    Just keep eyes, the ears and, just remember, brain available while negotiating while using the ndia.This is because that there are plenty of dubious players that supply cheap automotive rental reservations only to provide you with a car this really is hardly suitable to meet your needs.The very low Car private coach rentals inside India own provided the opportunity for these types of elements for you to explore and also exploit this vulnerable users.So, tips on how to protect your household from finding caught in this messy state of affairs? The reply to this tough question lies in just an individual word -- 'diligence'.Just keep eyes, the ears and, just remember, brain available while negotiating while using the car hire agent.Firstly, you has to be clear in mind about the prerequisites - that i.e., whether your family needs are provided by compact SUV or perhaps medium MUV.Should the small car can be your requirement, make sure the automobile comes with all the brand new safety instruments like fit belts, electric power brakes, crash shock absorbers and so forth.Remember Asia car rentals can be cheapest nevertheless, you must discount hard for your lowest quote to have appropriate automotive.We usually get influenced by Low-priced car leases.India is rich in such cheap providers.But the most effective is one that offers excellent service located at reasonable cost.While trying to find cheap motor vehicle rentals around India on-line, make sure you may spend adequate time looking for a reputed agent struggling with car accommodation.India has lots of roads additionally, the choice on the vehicle as well as the car procurment agent depends a whole lot on the caliber of roads you most likely are travelling.A prior know-how about computers the location always will come in handy such situations.Simple basic wise practice is all that is required for yourself to land a good safe together with economical contend with the car or truck rental materials..

  • imiltsiass

    asy to get into Victoria Key or JC Pennys as well as spend on a thousand dollars for a few items should you not prioritize and even set a good limit.
    The easiest perhaps the process that will narrow decrease your selection by far the most is obtaining your volume.Although labels and which kind of womens apparel you would like can vary bigger, generally any size remains exactly the same for many products.Then when you go to a retail store, it either has an individual's size or very easy.If very easy, you are able to either await it to come in any size, check out a different retail store or select a diffeasy to get into Victoria Key or JC Pennys as well as spend on a thousand dollars for a few items should you not prioritize and even set a good limit.

    The easiest perhaps the process that will narrow decrease your selection by far the most is obtaining your volume.Although labels and which kind of womens apparel you would like can vary bigger, generally any size remains exactly the same for many products.Then when you go to a retail store, it either has an individual's size or very easy.If very easy, you are able to either await it to come in any size, check out a different retail store or select a different thing.

    Another phase containing made option just inside the past couple of decades is without a doubt Internet purchasing.With the web continuously expanding and more stores opening an via the internet shopping internet site, it has become increasing popular to shop online.If you shop online, you contain a much bigger selection to select from and a great endless variety of stores to choose from.There would be the downsides and even risks of having the unsuitable item sent, having to cover shipping and having to wait in your item to always be shipped.On the other hand, it opens the door to a much bigger selection in womens apparel than previously.

    With pretty much everything said, it is right now your decision to settle on what brand you like most as well as what style you would like.Whether you desire basketball and / or tennis women active wear is really a decision to make.Do you want a black or simply brown and white ladies business agree with? Are you looking for a comfortable nightgown and also sexy females intimate nighties? These are all questions you'll need to ask by yourself when seeking out womens clothes, but typically the sky is the limit intended for what the stores have to offer you.

  • fakehandbags

    here will be restrictions to the amount and variety of wedding decorations which they can display and you will need to know this unique beforehand.Sometimes there may also be restrictions in noise all this is something verify, customer know when your policies.If you know what the polices are but like the big event venue it really is fairly effortless adapt a decorations and even wedding prefer to fit your venue and its particular restrictions.However you prefer to know thihere will be restrictions to the amount and variety of wedding decorations which they can display and you will need to know this unique beforehand.Sometimes there may also be restrictions in noise all this is something verify, customer know when your policies.If you know what the polices are but like the big event venue it really is fairly effortless adapt a decorations and even wedding prefer to fit your venue and its particular restrictions.However you prefer to know this give you and not final so it may be very useful to ask premature.

    Parking
    This is certainly something considering when you look at the venue.Maybe there is enough storing space for everybody who will be attending your wedding day.Expecting friends and family to park far off and walk can definitely be quite a lot to consult.You want the presentation to become as easy as is feasible and a good amount of parking can help your friends and family feel welcomed.This is especially those friends and family that turn up fashionable late into the event.

    On potential marriage ceremony venue sites before hand you may learn plenty and consequently make the decision determined by your collected information.The most essential concern is how to feel regarding the site.Again have faith in your instinct in that arena and make certain the web page is a factor that speaks you.It have to be a lace that you could easily think about yourself having a wedding at.

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">