Must Read Tip To Solve Following Problem :
- First one must understand that - sizeof is not an function it’s an operator.
- Inside C Program we can calculate size of all data types including user defined and in built data types.
- However Sizeof Operator cannot calculate Size when we pass function name as parameter.
- However Sizeof Operator can take address of Function because in c “Address of variable or function” is always of type integer.
Now try to solve following question by referring above tips -
#include<stdio.h> int main() { printf("\n%d",sizeof(&main)+2); return(0); }
Output with Explanation
4
Explanation :
- &main will gives us Address.
- sizeof will treat this address as “integer”.
- Size of Integer = 2 bytes (in Turbo C/C++ Compiler)
- Therefor output is 4.