Write a program to calculate the size in bytes required by data items and in-built data types of C using the "sizeof" operator.

C Programming Language Operators and Enums in C Language (Article) Operators and Enums in C Language (Program)

1945

Program:

/*
 Program:  Write a program to calculate the size in bytes required by data
  items and in-built data types of C using the "sizeof" operator. 
  
 Author: www.atnyla.com  
 
*/ 

#include "stdio.h"  
int main()
{
	printf("char size = %d bytes\n", sizeof(char));
	printf("short size = %d bytes\n", sizeof(short));
	printf("int size = %d bytes\n", sizeof(int));
	printf("long size = %d bytes\n", sizeof(long));
	printf("float size = %d bytes\n", sizeof(float));
	printf("double size = %d bytes\n", sizeof(double));
	printf("1.55 size = %d bytes\n", sizeof(1.55));
	printf("1.55L size = %d bytes\n", sizeof(1.55L));
	printf("HELLO size = %d bytes\n", sizeof("HELLO"));
	return 0;
} 

Output:

char size = 1 bytes
short size = 2 bytes
int size = 4 bytes
long size = 4 bytes
float size = 4 bytes
double size = 8 bytes
1.55 size = 8 bytes
1.55L size = 12 bytes
HELLO size = 6 bytes
Press any key to continue . . .

Explanation:

None

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.