Data Types in C++

There are lots of data types in C++ and each data type has pre-defined limit of length and type of data it can hold. Few Data types such as int, char, float, etc are described in this post and also sample code is provided with which you can find out length of bytes supported by any given data type. You can even confirm the range of data types using simple program as displayed in the same code below.

// DataTypes.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){int iInteger1=2147483647;int iInteger2=iInteger1+1;cout << "Value of iInterger1 is " << iInteger1<< "n";cout << "Value of iInterger2 is " << iInteger2<< "n";cout << "-----------------------------------------------n";char vChar1, vChar2;vChar1='A';vChar2='0';cout << "Value of iChar1 is " << vChar1<< "n";cout << "Value of iChar2 is " << vChar2<< "n";cout << "-----------------------------------------------n";float vFloat1=22.0 / 7;cout << "Value of iFloat1 is " << vFloat1<< "n";cout << "-----------------------------------------------n";cout << "Size of int is " << sizeof(int) << " Bytes.n";cout << "Size of char is " << sizeof(char) << " Bytes.n";cout << "Size of float is " << sizeof(float) << " Bytes.n";cout << "nMore Tutorials at TapKaa.comnn";return 0;}

The above code provides really useful information about various data types in C++. Yes there are many more data types and this sample code provides you ways in which you can check data length and range of values supported by any given data type. Data types can even be casted to each other and this website will provide another dedicated post for providing information about data casting.

Note in the above C++ code, value of an int variable is assigned and another int variable is declared. The second int variable is assigned the sum of the value of first variable plus one. The above sample code also displays how you can assign characters to char data types and finally float data type is described which can store information as per it’s length. Finally usage of the sizeof operator is described which tells how many bytes a particular data type or variable will occupy when the application is run on the Operating System.

C++ Data Types

C++ Data Types

Yes Information of Data Types is one of the basic information about C++ and yet lots of articles have been posted already on this website before describing data types. As there are lots of data types, it can be a little bit hard to remember every data type and as C++ supports lots of functionality like operator overloading, you can even create your own custom data type. The Data Types defined by the C++ Language are displayed in the Visual Studio Integrated Development Environment in blue color by default and are called keyboard. You cannot create a variable name with the name of C++ Data type like int, long, char, etc.