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

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

👁 2,049 Views
💻 Practical Program
📘 Step Learning
Write a program to calculate the size in bytes required by data items and in-built data types of C using the "sizeof" operator.

💻 Program Code

/*
 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;
} 
                        

🖥 Program 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
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.