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.


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


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)


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)


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.


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

  • Bamboo Palm - The Beautiful Lovable Palms

    The bamboo palm (chamaedorea seifrizii) is a beautiful, commonly kept houseplant that works as an air purifier. It has a bamboo like stem and a few of these stems grow from an underground bulb of roots. Leaves are flat,...

  • My Favorite Palm Trees - 10 Top Palms

    I am a big lover of palm trees and here I am going to share some of my favorite palm trees with you. Kentia palms are beautiful palms native to the Lord Howe island of Australia. Now, these plants have reached almost...

  • 1000 Interesting Facts

    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...


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