Home / Programs / Find the size of various types of datatypes in c programming language
Programming Example

Find the size of various types of datatypes in c programming language

👁 1,011 Views
💻 Practical Program
📘 Step by Step Learning
sizeof operator in c programming language

Program Code

// sizeof operator in c programming language
// find the size of various types of datatypes

#include<stdio.h>
void main(){

printf("size of int: %d byte\n",sizeof(int));
printf("size of character: %d byte\n", sizeof(char));
printf("size of float: %d byte\n", sizeof(float));
printf("size of double: %d byte\n", sizeof(double));
printf("size of long double: %d byte\n", sizeof(long double));


printf("size of signed: %d byte\n", sizeof(signed int));
printf("size of unsigned int: %d byte\n", sizeof(unsigned int));

printf("size of short int: %d byte\n", sizeof(short int));
printf("size of long int: %d byte\n", sizeof(long int));

printf("size of signed short int: %d byte\n", sizeof(signed short int));
printf("size of unsigned short int: %d byte\n", sizeof(unsigned short int));

printf("size of signed long: %d byte\n", sizeof(signed long int));
printf("size of unsigned long int: %d byte\n", sizeof(unsigned long int));  

}

Output

size of int: 4 byte
size of character: 1 byte
size of float: 4 byte
size of double: 8 byte
size of long double: 12 byte
size of signed: 4 byte
size of unsigned int: 4 byte
size of short int: 2 byte
size of long int: 4 byte
size of signed short int: 2 byte
size of unsigned short int: 2 byte
size of signed long: 4 byte
size of unsigned long int: 4 byte
Press any key to continue . . .

Explanation

sizeof operator in c programming language

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.