Recall Forecast-then-Verify: before reading the table, what is
sizeof(long) on 64-bit Windows?
4 bytes (LLP64). On 64-bit Linux it's 8 (LP64). The whole point of the lesson.
Recall Why is
sizeof(char) == 1 always true?
Because sizeof is defined to count in units of char. A char is "1 char" by definition, regardless of how many bits it has.
Recall Feynman: explain to a 12-year-old
Imagine boxes for holding numbers. C says "I'll give you a box, and it'll be at least this big, but on a small toy computer it might be smaller and on a big computer bigger." That's int. If you need a box that's exactly 4 slots wide no matter which computer — so two computers can mail boxes to each other and they line up perfectly — you ask for int32_t. sizeof is just a ruler that measures how many tiny slots a box uses.
Dekho, C language ek important cheez clearly nahi batati: int, long waghaira ka exact size kitna hoga. Woh sirf minimum guarantee deti hai (jaise int kam se kam 16-bit) aur ek ordering (char ≤ short ≤ int ≤ long). Asli size depend karta hai compiler + CPU + OS pe — isko ABI kehte hain. Isi wajah se same code different machine pe alag behave kar sakta hai. Classic trap: 64-bit Linux pe long = 8 bytes, lekin 64-bit Windows pe long = sirf 4 bytes. Agar aapne maan liya ki long hamesha 8 hai, to Windows pe bug aa jayega.
sizeof ek operator hai (function nahi), jo compile-time pe bata deta hai ki koi type kitne char-units leta hai. Isliye sizeof(char) hamesha 1 hota hai — kyunki measurement hi char ke units mein hoti hai. Print karte waqt %zu use karo, kyunki return type size_t hota hai (unsigned).
Jab aapko exact width chahiye — network packet, file format, hardware register — tab #include <stdint.h> karke int32_t, uint8_t, int64_t use karo. Inke naam mein hi number likha hai, to size guaranteed hai har platform pe. Mnemonic simple: jis type ke naam mein number hai (32, 64) uska size pakka; jiske naam mein number nahi (int, long) uska size pakka nahi.
Ek aur common galti: function ke andar sizeof(arr)/sizeof(arr[0]) se array length nikalna. Function mein array pointer ban jata hai (decay), to sizeof pointer ka size deta hai, array ka nahi — count galat aata hai. Isliye length alag se pass karo. Ye chhoti chhoti baatein hi 80% portability bugs bachati hain.