SIZEOF

the "sizeof" operator identifies the number of bytes allocated for a given data type or variable. it is crucial for the following:

  • Memory Management: Understanding how much memory a program uses is vital for efficient allocation and avoiding errors.

  • Data Structure Design: When building arrays, structures, or unions, knowing the size of their components is essential for planning memory layout.

  • Low-Level Operations: In scenarios involving pointers, memory manipulation, or hardware interaction, sizeof helps ensure correct alignment and data access.

USAGE

this operator MUST not be used with parentheses when the argument is a literal or a value. However, if the argument is a "type" the use of parentheses is a MUST.

LITERAL/VALUE

#usage on a litral or a value
int i; char c;
i = sizeof c;

TYPE

#usage on a type
i = sizeof(char);

ARRAYS

Last updated