Nearby lessons

33 of 124

C - sizeof Operator

sizeof Operator is one of the foundational topics in C programming. This lesson explains The sizeof Operator — Memory Sizes and Program: size of every basic type with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.

The sizeof Operator — Memory Sizes

sizeof tells you exactly how many bytes a data type takes on your computer. Run it and see your own machine's sizes:

In simple words: sizeof is a weighing machine for data types — it tells you exactly how many bytes a type needs on your computer.

Program: size of every basic type

Trainer's Note: Sizes can change with the compiler and operating system. On 64-bit Linux, long is usually 8 bytes; on Windows it is 4 bytes (as shown above). That is exactly why sizeof exists — it prints the truth for your machine. char is the one type the C language fixes: it is always 1 byte.
Example02
CCode Cell
1#include <stdio.h>
2 
3void main()
4{
5 printf("int : %d bytes\n", sizeof(int));
6 printf("float : %d bytes\n", sizeof(float));
7 printf("double : %d bytes\n", sizeof(double));
8 printf("char : %d byte\n", sizeof(char)); // char is always 1 byte
9 printf("short : %d bytes\n", sizeof(short));
10 printf("long : %d bytes\n", sizeof(long));
11}
Output

int    : 4 bytes
float  : 4 bytes
double : 8 bytes
char   : 1 byte
short  : 2 bytes
long   : 4 bytes
      
📝 Key Takeaways
  • Tokens = keywords, identifiers, constants, operators, special symbols.
  • Constants never change; variables can hold different values.
  • Identifier rules: start with letter/underscore, no spaces/symbols, no keywords.
  • Basic data types: int, float, double, char — each with its own example program.
  • Declaration = type + name; initialization = giving a value.
  • sizeof tells the memory size of a type.

🧠 Test Your Knowledge

1 Questions
Progress: 0 / 1