Given four types of variables, namely int, char, float and double, the task is to write a program in C or C++ to find the size of these four types of variables.
Input: int Output: Size of int = 4 Input: double Output: Size of double = 8
Here is a list of all the data types with its size, range and the access specifiers:
|Data Type||Memory (bytes)||Range||Format Specifier|
|short int||2||-32,768 to 32,767||%hd|
|unsigned short int||2||0 to 65,535||%hu|
|unsigned int||4||0 to 4,294,967,295||%u|
|int||4||-2,147,483,648 to 2,147,483,647||%d|
|long int||4||-2,147,483,648 to 2,147,483,647||%ld|
|unsigned long int||4||0 to 4,294,967,295||%lu|
|long long int||8||-(2^63) to (2^63)-1||%lld|
|unsigned long long int||8||0 to 18,446,744,073,709,551,615||%llu|
|signed char||1||-128 to 127||%c|
|unsigned char||1||0 to 255||%c|
To find the size of the four variables:
- The four types of variables are defined in integerType, floatType, doubleType and charType.
- The size of the variables is calculated using the sizeof() operator.
Below is the C and C++ program to find the size of int, char, float and double data types:
Size of int is: 4 Size of char is: 1 Size of float is: 4 Size of double is: 8
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- size of char datatype and char array in C
- Difference between float and double in C/C++
- Modulus of two float or double numbers
- C Program to find size of a File
- What is the difference between single quoted and double quoted declaration of char array?
- C program to print a string without any quote (singe or double) in the program
- Lex Program to accept a valid integer and float value
- Python 3 | Program to print double sided stair-case pattern
- Program to concatenate two given Matrices of same size
- C Program for Maximum size square sub-matrix with all 1s
- Java Program to Multiply two Matrices of any size
- C / C++ Program for Median of two sorted arrays of same size
- Program that receives a number and prints it out in large size
- What's difference between char s and char *s in C?
- What is the difference between "char a" and "char a"?
- How to find size of array in C/C++ without using sizeof ?
- C Program for Program to find area of a circle
- Difference between const char *p, char * const p and const char * const p
- Program to find sum of 1 + x/2! + x^2/3! +...+x^n/(n+1)!
- Program to find sum of series 1 + 1/2 + 1/3 + 1/4 + .. + 1/n
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.