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

  • nrayeinmmi

    To provide a matter regarding fact most web marketers invest $1000`s each year into his or her business, seeking advertising tool`s and income opportunities that will them secure the edge over his or her's competition.I need fallen victim to this a couple of times myself within the last several several years of marketing online.
    How can you know you can make a fortune online with out a large listing or internet marketer website of your.A the actual guru`s say that it`s impossible without these "2 vital components".Let me fill everyone in on the completely free technique to get above 10, 000 100 % free affiliate websites.In fact will be possible to market many different niches without paying some dime.All you must do is drive traffic that will these internet marketer sales pages to get started earning money from home.
    Now mind you that the majority of these sites can pay you a one time commission per sale an individual make, different from residual earnings programs, which will pay a person monthly.AlthoughTo provide a matter regarding fact most web marketers invest $1000`s each year into his or her business, seeking advertising tool`s and income opportunities that will them secure the edge over his or her's competition.I need fallen victim to this a couple of times myself within the last several several years of marketing online.

    How can you know you can make a fortune online with out a large listing or internet marketer website of your.A the actual guru`s say that it`s impossible without these "2 vital components".Let me fill everyone in on the completely free technique to get above 10, 000 100 % free affiliate websites.In fact will be possible to market many different niches without paying some dime.All you must do is drive traffic that will these internet marketer sales pages to get started earning money from home.

    Now mind you that the majority of these sites can pay you a one time commission per sale an individual make, different from residual earnings programs, which will pay a person monthly.Although you can get some that supply you residual income too.Most of those free one time sale sites can be just while profitable for you, with numerous affiliates earning throughout $10, 000 each and every month.

    Do i guarantee the amount of you will make with those sites? Very little, that ?s dependent upon you! I can`t push traffic towards these sites for everyone and I JUST surely can`t put in place the effort for you.But We can guarantee that when you use effort with the help of testing, you do make money.

    All right, I`ll explain all you need to understand to accessibility over 10, 000 cost-free affiliate sales pages to help make money with.It`s labeled as Click Financial institution! Big astonish heh? Clearly, you will be amazed at just how countless marketers, start looking right previous this incredible free affiliate program.

    Please click Bank functions great with traffic.This opportunity can certainly make you retire early, if you happen to learn to understand it.Most definitely i'll not bore you with details, but Click on Bank works exceptionally well with google adwords.Adwords is usually a whole different beast and I possibly could actually prepare a e-book on what you must know, to be able to lose your shirt utilizing it.

    As a result, I will stay with the important thing.No web page, no number, no issue.You simply log in and search for the solutions or packages that you need to market from more than a selection 10, 000.

    It get`s better.You simply use your Click Loan provider username for you to instantly make a your own affiliate internet site / web page and any off promoting.No complications whatsoever and clickbank uses your i.d.to monitor sales comprised of each web site.

    When you're serious about earning a sizable income over the internet, but actually can`t afford to fork out a once a month fee to partake of an internet affiliate program for the upgraded web site and commission`s, We highly recommend joining Click Bank free of charge and marketing their services, services in addition to programs.

  • expeditiongoose

    ill beat out every one of the other probable buyers.Everbody knows that arranging for a mortgage before shopping a wonderful idea.If there's no need any feel with acquiring houses, it really is definitely still an opportunity to flip over some Garland, Texas real-estate.It just normally takes longer to get the right premises and funding.
    The trick to earning Garland, TX real-estate flipping a good profitable venture is almost always to work rapidly.The faster you possibly can make the progress and resell home, the a higher cost you will make.If you work over time and get months ill beat out every one of the other probable buyers.Everbody knows that arranging for a mortgage before shopping a wonderful idea.If there's no need any feel with acquiring houses, it really is definitely still an opportunity to flip over some Garland, Texas real-estate.It just normally takes longer to get the right premises and funding.

    The trick to earning Garland, TX real-estate flipping a good profitable venture is almost always to work rapidly.The faster you possibly can make the progress and resell home, the a higher cost you will make.If you work over time and get months mention a few paint some sort of wall, your profit will probably be eaten into during a long period of work.So take out all any stops, and work as efficiently as they can be for the short time that your own home is as part of your possession.By working your fingers in the bone for a time, you shall be allowing your own self time afterwards to enjoy your newly found profits.This is a great project to get results on in your spouse, and afterwards it is possible to enjoy a vacation using the money both of you worked which means hard to help you earn -- or put the benefits into one other house it is easy to flip.

    If you opt that flicking Garland real estate is a booming enterprise venture that you desire to be linked to, then learn to watch the $ 64000 estate postings today.Just procrastinate patiently before you see something inside of your price assortment.Look it all over to see if you can actually do something to easily improve it all and raise its sales agreement value.In the event the Garland, Texas real estate market looks promising, then go for it! By supplementing with calculated associated risk, you may find a powerful way to bring in more assets.

  • nrayeinmmi

    trate on the quite a few advertisements that to appear on your web site.This may be a put off for lots of visitors who go to your websites.They can look elsewhere because the irritating pop-ups or perhaps adverts of which keep appearing in the future.So how might one characteristics consequences involving free hosting services? By deciding on paid though cheaper web host services certainly! That makes us to another location question where you get cheap web host? There are numerous companies that comes with cheap internet hosting solutions.However there are certaitrate on the quite a few advertisements that to appear on your web site.This may be a put off for lots of visitors who go to your websites.They can look elsewhere because the irritating pop-ups or perhaps adverts of which keep appearing in the future.So how might one characteristics consequences involving free hosting services? By deciding on paid though cheaper web host services certainly! That makes us to another location question where you get cheap web host? There are numerous companies that comes with cheap internet hosting solutions.However there are certain tricks to assist you to decide that this best one for your needs is.Space.The earliest requirement is certainly space.If however, you have recordsdata that occupy an excessive amount disk place or bandwidth, then its far better choose an agency that creates a large site that allows downloads likewise.Email.Most web hosting service companies will give email support 100 % free.One thing to not overlook while considering where we can get cheap web host is that will storage together with viewing with emails is bound to take up disk spot.Customer Company.Most web host service services are notorious on their customer service.Therefore, it contributes greatly to purchase a vendor that features good assist.Downtime Challenges.The very last thing you want is the platform for your website experiencing downtime troubles.So while in need of where we can get cheap web hosting service consider the volume of uptime the host brings you.Uptime will need to ideally get 99.5% to help qualify a fabulous hosting provider to be good.So, your site will likely be inaccessible for at 7.2 minutes daily.Want to receive Cheap Web hosting service .

  • aditya.dharmasagar

    what is the difference between using “using namespace std” globally and locally ?? it would be easy if we declare it globally right ?? so that in every function we need not declare it again and again ???

  • aditya.dharmasagar

    what is the difference between using “using namespace std” globally and locally ?? it would be easy if we declare it globally right ?? so that in every function we need not declare it again and again ??

    • rameye

      Think of what you are giving up when you use it globally. You then put yourself in the firing line for your own names colliding with names from the namespace you turned it all over to.

      What if you had written some code that had a function name cout or cin? Now it doesn't work because you gave the name ownership away to another namespace.

  • kijonrwslows

    have the ability to take further benefit for a completely new American passion:saving with the help of online researching!
    Suggestion 1:Do not buy Craigslist and ebay.We many know sale seem want such very much, and its basic get trapped in this emotion about auction.Point is, auction web-sites like Craigslist and ebay and Ubid have grown to be saturated utilizing buyers AND ADDITIONALLY sellers, so almost any discount located is easily sought just by re-distributors who start being active .their personal markups for the purchase.The via the internet marketplace contains enough people in existence that you could end up spending many extra dollars for those same things obtained in your hometown mall! Dont make it possible for your emotions become involved these will not be the best places with the aware consumer.
    Suggestion 2:In no way pay retail store.Take this unique scenario:You look for something you need to buy, maybe the hottest craze or maybe fad like the Ipod.In the event you really pay thhave the ability to take further benefit for a completely new American passion:saving with the help of online researching!

    Suggestion 1:Do not buy Craigslist and ebay.We many know sale seem want such very much, and its basic get trapped in this emotion about auction.Point is, auction web-sites like Craigslist and ebay and Ubid have grown to be saturated utilizing buyers AND ADDITIONALLY sellers, so almost any discount located is easily sought just by re-distributors who start being active .their personal markups for the purchase.The via the internet marketplace contains enough people in existence that you could end up spending many extra dollars for those same things obtained in your hometown mall! Dont make it possible for your emotions become involved these will not be the best places with the aware consumer.

    Suggestion 2:In no way pay retail store.Take this unique scenario:You look for something you need to buy, maybe the hottest craze or maybe fad like the Ipod.In the event you really pay the charge that Apple is providing? No! You'll find many specials and coupons for ones same purchase through typing, for instance, ipod vouchers int The search engines.Spend a little time searching via the top twenty to something like 20 results, youre sure to obtain the same product on a significant price cut.Sometimes, by writing a online survey or becoming a member of an mail list, youll receive additional savings a lot of times you may also get any product at zero cost!

    Suggestion 3:Overcome your fast gratification motivation.Just say it, buying an issue always produces a beneficial feeling while you cant hold on to get pleasure from that fresh purchase.Anything youre buying in the mall to make the same superior feeling may well usually end up found for just a huge lower price online.You have to be ready wait for those short 2-5 days so it takes designed for shipping.Its undeniably worth all the savings to in a position to control any emotions and hold-up until this arrives via UPS!

    Suggestion 4:Look out for excessive shipment charges.Many situations retailers cut their costs to find the sale ; however , charge alot more for delivery.Make sure to confirm the remaining cost to guarantee you didnt have any unwarranted costs.You will typically find also shipping put up at several online token sites.Sometimes this shipping can certainly cost a lot more than your order!

    Suggestion 5:On the internet coupons:Were you conscious of online voucher websites which happen to have discount and additionally promotion computer codes to many internet retailers? These varieties websites have always contemporary discount delivers arranged just by category or simply store, to help you always look for something available for purchase.Its not really a way to have a good put up but you can also find some on the free shipping and delivery offers mentioned in word of advice 4.You need to be careful to be sure for a bonus coupon before doing any word wide web purchase.Its an easy way to uncover extra benefits.

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="">