What does the sizeof()
operator do in C?
a) It returns the size of a variable or data type in bytes
b) It allocates memory
c) It deallocates memory
d) It returns the address of a variable
Answer:
a) It returns the size of a variable or data type in bytes
Explanation:
The sizeof()
operator in C is used to determine the size, in bytes, of a variable or data type. This operator is particularly useful when working with memory allocation functions like malloc()
or when you need to know the size of a structure, array, or data type at runtime. For example, sizeof(int)
returns the size of an integer on the system, which is typically 4 bytes on most modern architectures.
Understanding sizeof()
is essential for memory management and ensuring that programs allocate the correct amount of memory based on the data types being used.