C++ Tutorial – Data types

C++ practically offers most of the necessary data types except for a basic data type string. This is a big trouble in C++ without such a good feature.

Anyway, this c++ tutorial will discuss the basic data types necessary for c++ programming.

C++ tutorial – Number data types:


This int keyword is used to declare integers, whole numbers either positive or negative. Most of the compilers treat this with a size of 2 bytes. i.e.,integer of 16 bits length. The following statement shows how the variables of int type are declared.

int var1;
int var11 = 10; //Initialization for c++ tutorial


This long keyword is used for declaring longer numbers. i.e, numbers of length 32 bits.


This keyword float is used to declare floating point decimal numbers. A sample declaration would be,

float var2; //Sample declaration for float

C++ tutorial – char data types:


This keyword is used to declare characters. The size of each character is 8 bits. i.e., 1 byte. The characters that can be used with this data type are ASCII characters.


This is not a basic data type with C++. Instead array of the char data type should be used for a string variable.

char strvar1[200];
char strvar2[]="string can also be initialized like this for the C++ Tutorial";

Otherwise the string class provided in Standard Template Library can also be used.

There are some more obscure types too. For example, date. In C++ we cannot use date type right away. This has to be converted to a string or integer for outputs etc., Also, this data type is not available with all compilers. As of now, all of the windows C++ compilers provide this type. We’ll deal with this date separately in another C++ Tutorial.