Data Types in C++

What is a data type?

When we wish to store data while writing a C/C++ program, we need to tell the computer what kind of data it is. For example, whether it is a charactor or an integer. With the help of data types we can tell computer what kind of data we are going to store in a perticular variable.

Character

Known as: char

Declaration: char variable-name;

Function: Takes one character at a time as input e.g 'y', 'K', 'A' , 'a' etc.

Size: 1 Byte (8 bits)

Range: -128 to 127

Float

Known as: float

Declaration: float variable-name;

Function: Takes floating point values as input e.g. 32.973, 901.675 etc.

Range: 3.4 e-38 to 3.4 e+38

Size: 4 Bytes (32 bits)

Integer

Known as: int

Declaration: int variable-name;

Function: Takes integer or whole number values as input e.g. 46, 2832, -56 etc.

Size: 2 Bytes (16 bits)

Range: –32,768 to 32,767

Variations: unsigned int, short, long, unsigned short, unsigned long

Please note that when we say integer, short integer and long inteder; that means we are talking about the signed variables. When mentioning unsigned, it is necessary to write unsigned with them.

In signed integers one bit out of total 16 bits is reserved for a minus sign, in case the value that is to be stored can be negative. The reserved bit for sign is the first bit. The range of unsigned integers start from 0 as the values can not be below zero.

Long Integer

Known as: long

Declaration: long variable-name;

Function: Used for storing large numerical values.

Range: -2,147,483,648 to 2,147,483,647   

Size: 4 Bytes (32 bits)

Double

Known as: double

Declaration: double variable-name;

Function: Can store extremely large numerical values.

Range: 1.7e-308 to 1.7e+308

Size: 8 Bytes (64 bits)

Please note that 'long double' has a same size and range as double.

Note

This hub is to help people who already know a bit of programming. If you don't know the basics of programming, this might sound Greek to you. So, please don't curse me in case you don't get it. I wrote this hub because I was teaching programming to BS students and did not find very good resources on the web related to the data types of C++ especially there was no good resource for beginners. I might further illustrate C++ programming in the comming hubs.

More by this Author

  • Pain Quotes
    17

    Here I am sharing a collection of pain quotes with you all.

  • Palm Trees Propagation - Growing New Palm Trees
    1

    Growing new plants saves you money and it is fun. It is an amazing experience watching your seeds turning into seedlings and then turning into trees. Here are two main methods of propagating palm trees. You can grow...

  • 1000 Interesting Facts
    65

    I have collected these random facts from various sources on the internet(like Wikipedia), so they may or may not be true. Now please proceed to reading these interesting random bits. Butterflies cannot fly if their...


Comments

No comments yet.

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working