Data Types in C++

VHDL Programming


For C++ Programming we must have knowledge About the Data Type. This tutorial help to understand the various C++ data types.

What is a data type ? 

When we store data in a C++ program, such as a whole number or a character, we have to tell the compiler which type of data we want to store. The data type will have characteristics such as the range of values that can be stored and the operations that can be performed on variables of that type.


Type Name Bytes Other Names Range of Values
int * signed,
signed int
System dependent
unsigned int * unsigned System dependent
__int8 1 char,
signed char
–128 to 127
__int16 2 short,
short int,
signed short int
–32,768 to 32,767
__int32 4 signed,
signed int
–2,147,483,648 to 2,147,483,647
__int64 8 none –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
bool 1 none false or true
char 1 signed char –128 to 127
unsigned char 1 none 0 to 255
short 2 short int,
signed short int
–32,768 to 32,767
unsigned short 2 unsigned short int 0 to 65,535
long 4 long int,
signed long int
–2,147,483,648 to 2,147,483,647
long long 8 none (but equivalent to __int64) –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
unsigned long 4 unsigned long int 0 to 4,294,967,295
enum * none Same as int
float 4 none 3.4E +/- 38 (7 digits)
double 8 none 1.7E +/- 308 (15 digits)
long double same as double none same as double
wchar_t 2 __wchar_t 0 to 65,535



Fundamental types 

C++ provides the following fundamental built-in data types:

Boolean, character, integer and floating-point. It also enables us to create our own user-defined data types using enumerations and classes.

1. Boolean Type 
The Boolean type can have the value true or false. For example:


If a Boolean value is converted to an integer value true becomes 1 and false becomes 0.

If an integer value is converted to a Boolean value 0 becomes false and non-zero becomes true.

2. Character Type 

The character type is used to store characters – typically ASCII characters but not always. For example:


Note how a character is enclosed within single quotes. We can also assign numeric values to variables of character type:


We can declare signed and unsigned characters, where signed characters can have positive and negative values, and unsigned characters can only contain positive values.


Note that if we use a plain char, neither signed nor unsigned:


A char is guaranteed to be at least 8 bits in size. C++ also provides the data type wchar_t, a wide charactertype typically used for large character sets.

An array of characters can be used to contain a C-style string in C++. For example:


3. Integer Types 

The integer type is used for storing whole numbers. We can use signed, unsigned or plain integer values as follows:


Like characters, signed integers can hold positive or negative values, and unsigned integers can hold only positive values. However, plain integer can always hold positive or negative values, they’re always signed.

You can declare signed and unsigned integer values in a shortened form, without the int keyword:


Integer values come in three sizes, plain int, short int and long int.


You can declare short and long integer values in a shortened form, without the int keyword:


You can have long and short signed and unsigned integers, for example:


4. Floating-Point Types 

Floating point types can contain decimal numbers, for example 1.23, -.087. There are three sizes, float (single-precision), double (double-precision) and long double (extended-precision). Some examples:


The range of values that can be stored in each of these is defined by your compiler. Typically double will hold a greater range than float and long double will hold a greater range than double but this may not always be true. However, we can be sure that double will be at least as great as float and may be greater, and long double will be at least as great as double and may be greater.

5. Enumeration Type 

An enumeration type is a user defined type that enables the user to define the range of values for the type. Named constants are used to represent the values of an enumeration, for example:


The default values assigned to the enumeration constants are zero-based, so in our example above monday == 0, tuesday == 1, and so on.

The user can assign a different value to one or more of the enumeration constants, and subsequent values that are not assigned a value will be incremented. For example:


Here, orange will have the value 8 and kiwi 9.

6. Class Type 

The class type enables us to create sophisticated user defined types. We provide data items for the class type and the operations that can be performed on the data. For example, to create a square class that has a data item for size, and provides draw and resize operations:


Coding Talks

C++ Programming

You Need "Data Types in C++" ???

"Data Types in C++" (Source Code / Report / PPT) Totally belong to CodingTalks Team and We always ready to Share our Stuff with our users. If you are Very Much Interested on This Topic Then you must Leave a Comment what Exactly you Looking For Or Send us Email to get Full Information.

Coding Talks

Filed in: C/C ++ Tags: , , , , , , , ,

Get Updates

Share This Post

Related Posts

Leave a Reply

Submit Comment

© 2018 CodingTalks. All rights reserved.

Warning: filemtime(): stat failed for /home/codingtalks/public_html/wp-content/plugins/floating-social-share-bar//js/waypoints.min.js in /home/codingtalks/public_html/wp-content/plugins/floating-social-share-bar/floatingshare.php on line 213