Master the fundamental concepts of c programming deep dive through this focused micro-challenge.
The sizeof operator reports how many bytes a type or expression occupies. Clang and GCC evaluate it at compile time, which is why you can size static buffers and pass sizeof(int) * n to malloc without a runtime lookup. On a typical Linux x86-64 ABI, int is 4 bytes, long is 8 bytes, and every pointer is 8 bytes no matter what it points at.
Struct layout is not always the sum of field sizes. Compilers insert padding so each member aligns to its natural boundary. An int followed by a char often becomes 8 bytes, not 5. String literals include a null terminator, so sizeof("hello") is 6. Array sizes multiply: int[10] is 40 bytes when int is 4.
cLoading…
On x86-64 you typically see int: 4 and struct: 8 because of trailing padding.
For this exercise, you will print sizes for primitives, pointers, arrays, a struct, and a few expressions. This task asks you to treat sizeof as a diagnostic tool: once you know real sizes on your platform, stack allocation and heap requests stop being guesswork.
Write a C program that prints sizes of various types.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github