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