Data Types In C++ (cplusplus)

Data Types In C++

As we retain a no. in our memory so does a computer. A computer allocates memory for variables declared by the user. We need the computer to perform certain arithmetic operations on numbers so we store there values in variables declared.

Identifiers in C++

Each variable needs an identifier to differentiate itself from other variables. We can give any names we want to the variables as long as it is valid. In C and C++ there are certain rules to declare a variable.
1) Spaces or punctuation mark can't be a part of the variable. 2) It cannot begin with a digit , it must begin with a letter. 3) Single underscores are valid. 4) They are case-sensitive i.e. a is not equal to A.

C++ Data Types (fundamental)

We store the data in computer’s memory by declaring a variable but we need to tell the computer what kind of data the variable would store, since different data require different space in memory. In C++ the minimum amount of memory that can be allocated to a variable is 1 byte. A byte is small amount of memory and can store a small integer or a character.
Here are the data types available to us in C++.

Name detail size range
Short int It stores short integers. 2 bytes -32768 to 32767
int It stores integers. 4 byte -2^31 to 2^31-1
char It stores characters. 1byte -128 to 127
float It stores decimal values 4bytes +/- 3.4e +/- 38
double double floating point value. 8 bytes +/- 1.7e +/- 308
In general the size of the data types depends on the machine’s architecture i.e. 32 bit or 64bit and many other specifications. The above values are for a 32 bit machine.

Variable declaration in C++

In order to use a variable in c++, first we have to declare it by specifying the data type. Variable declaration follows certain rules. The syntax is Data type followed by the identifier. For example int a ; char ch ; two declarations have been made, 1st is an integer with indentifier ‘a’ and the other is a character with identifier ‘ch’. More than 1 variable of the same data type can be declared in the following way. int x,y,z ; float new_number,other_number ;

As soon as the variable is declared C++ language creates a buffer memory of the size of the data type in the computer.

Initialization of variables in C++

Once the variables have been declared , they are given the values that are further used in the program. The variables can be initialise at the time of declaration or later. The syntax for variable intialization is:

Type identifier (initial_value)

#include <iostream.h>
#include <conio.h>
Int main()
 int sum , a=3;
 float num=4.123;
 result= a+num
 cout <<result ;
 return 0;