Sample code:
int main(void) { printf ("size = %d\n", sizeof(main)); }
What is the returned value sizeof
applied to a function name, for example main
?
The function returns int , so it's sizeof(int) , which, on 32 bit systems is typically 4 bytes.
The sizeof() operator is a function which returns the size of any data type, expression, array, etc. It takes the data type or expression as a part of argument which is mandatory and returns the result which is size of that data type in bytes. If it is an array it will return the number of elements present in it.
Answer: sizeof returns the size of the type in bytes.
What is the sizeof() function in C? The sizeof() function in C is a built-in function that is used to calculate the size (in bytes)that a data type occupies in the computer's memory.
C standard forbids it - when compiled with gcc -pedantic
, it produces invalid application of ‘sizeof’ to a function type
warning.
However gcc
compiles it and returns 1
for sizeof(main)
, and it is not a size of function pointer.
It seems to be compiler-dependent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With