Sizeof in C | Usage Explained
The sizeof function is used to determine the size of a data type or variable in bytes. Its syntax is sizeof(data type/variable), and the return value is the number of bytes occupied by that data type or variable.
For example,
int x = 10;
printf("Size of int: %d\n", sizeof(int));
printf("Size of x: %d\n", sizeof(x));
This code will output:
Size of int: 4
Size of x: 4
This indicates that the int type occupies 4 bytes in the system, and the size of the variable x is also 4 bytes. The sizeof function is typically used in dynamic memory allocation and array operations to ensure proper allocation of memory space.