Whenever we create a program in any programming language and in that program we have to store any value from the user, then store it in the variable, we use the data type to create the variable.

Basic Data Type

There are many types of data used in the program like Numeric, Character, etc. C ++ has some basic data types, also known as built-in (pre-built) data types.

Integer Type(int)

It contains integer numbers in which decimals are not used. Numbers from -32768 to +32767 can be expressed in them. Long int is used for numbers greater than this. Generally, it takes 2-byte memory space.

Floating Type (Float)

These are for real numbers with decimal marks. Its range is from 10 -38 to 10 38. It takes 4 Byte Memory Space. However, with the double data type, we can use the range of 10 -308 to 10 308.

Character Type (Char)

Used to assign Alphanumeric data. It can have character input from 0 to 255. It is worth noting that data is used for use by closing it in a single quote (''). Like - 'A' or '2'

How to define the variable

Using any of the above data, we can create a variable like if we want to store the roll number of any student, then we can use the integer data type for that, see the example given below.

int rollno = 1001;

So whenever we want to create any variable, first we write its data type, then the name of the variable and then if you want to give a value, then it.

Variable naming rules

  1. Variables can be named with both Alphabet and Digit. But its first letter cannot be a digit.
  2. Space cannot be used in the name of a variable. Underscore can be used instead of space.
  3. No special symbols are used.
  4. Variable lengths can be up to 247 characters.
  5. Do not use Keywords in the name of the Variable.

Their limits and properties can be increased by giving basic data type int, char, or float a facelift. Data types received in the new form of Basic Data Type are called Type Modifiers.

Type Edit

Data Type can be upgraded as needed. The integer variable depends on the compiler if we get no. - If you want to store 40000 in the variable of int type then int data type is not suitable, its range is from -32768 to +32767. Hence no. - The updated form of int will be used for 40000. Which is long int. The type of long int, int will be called a modifier. Similarly, there are unsigned char or signed char type modifiers for char.

Long int and Short int

We know that the int data type has a fixed limit, so only certain values ​​can be stored in it. But many times during the calculation in the program, it goes beyond this limit in the value of Variable. Which leads to an error in the program. The limit of int depends on the compiler. The compiler is of 16 Bit and 32 Bit types. Int data type is a long int type modifier.

Which range from –2147483648 to +2147483647. Syntax to declare it is as follows -

Long int Variable_name; Or Long Variable_name;

Example: - long int num; Or long num;

Long int data type takes 4-byte space in memory. Using this data type slows down the process of the program. In contrast, the short int type modifier is used just like ordinary int. Its memory space is 2byte. Short int takes less space than int in an 82-bit compiler and this will make the program execute faster.





16 Bit Compiler

2 Byte

2 Byte

4 Byte

32 Bit Compiler

2 Byte

4 Byte

4 Byte

Signed int and unsigned int

The program sometimes requires an int Variable - or + sign. In this condition, we can declare it as an Unsigned int modifier type. In general, int limits range from -32768 to 32767. The value in the unsigned int data type will always be Positive. In this case, its limit varies from 0 to 65535. unsigned int modifier decoration do as follows -

Syntax:- Unsigned int Variable name ;

Signed int has the same value as opposed to unsigned. And on giving long before this, memory increases.

Signed Char and Unsigned Char

Signed Char is just like ordinary Char. Its range is from 128 to 127. The range of the unsigned char varies from 0 to 255.


I am an engineer by profession but being a blogger is my old day's dream to create my site for those who are more curious about my birthplace than I am coming from (India). the current city lives in Navi Mumbai, India

Post a Comment


Previous Post Next Post

نموذج الاتصال