C program to find the size of all data types using the sizeof operator
ADVERTISEMENTS
In this article, you will learn how to determine the size of all data types of c programming language.
You should have knowledge of the following topics in c programming to understand this program:
- C Data Types
- C
main
function - C
sizeof
operator - C
printf()
function
Source Code
// C program to find the size of all data types using the sizeof operator
#include <stdio.h>
int main() {
// Calculate the size of short int data type
printf("The size of short int: %ld bytes\n", sizeof(short int));
// Calculate the size of unsigned short int data type
printf("The size of unsigned short int: %ld bytes\n", sizeof(unsigned short int));
// Calculate the size of unsigned int data type
printf("The size of unsigned int: %ld bytes\n", sizeof(unsigned int));
// Calculate the size of int data type
printf("The size of int: %ld bytes\n", sizeof(int));
// Calculate the size of long int data type
printf("The size of long int: %ld bytes\n", sizeof(long int));
// Calculate the size of unsigned long int data type
printf("The size of unsigned long int: %ld bytes\n", sizeof(unsigned long int));
// Calculate the size of long long int data type
printf("The size of long long int: %ld bytes\n", sizeof(long long int));
// Calculate the size of unsigned long long int data type
printf("The size of unsigned long long int: %ld bytes\n", sizeof(unsigned long long int));
// Calculate the size of signed char data type
printf("The size of signed char: %ld byte\n", sizeof(signed char));
// Calculate the size of unsigned char data type
printf("The size of unsigned char: %ld byte\n", sizeof(unsigned char));
// Calculate the size of char data type
printf("The size of char: %ld byte\n", sizeof(char));
// Calculate the size of float data type
printf("The size of float: %ld bytes\n", sizeof(float));
// Calculate the size of double data type
printf("The size of double: %ld bytes\n", sizeof(double));
// Calculate the size of long double data type
printf("The size of long double: %ld bytes\n", sizeof(long double));
return 0;
}
Output
The size of short int: 2 bytes
The size of unsigned short int: 2 bytes
The size of unsigned int: 4 bytes
The size of int: 4 bytes
The size of long int: 8 bytes
The size of unsigned long int: 8 bytes
The size of long long int: 8 bytes
The size of unsigned long long int: 8 bytes
The size of signed char: 1 byte
The size of unsigned char: 1 byte
The size of char: 1 byte
The size of float: 4 bytes
The size of double: 8 bytes
The size of long double: 16 bytes
Explanation
In this given program, we used the sizeof
operator to determine the size of available data types in the c programming language.