C Interview Question Puzzle : Sizeof Operator is not Applicable to Function

Must Read Tip To Solve Following Problem :

  1. First one must understand that - sizeof is not an function it’s an operator.
  2. Inside C Program we can calculate size of all data types including user defined and in built data types.
  3. However Sizeof Operator cannot calculate Size when we pass function name as parameter.
  4. 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 :

  1. &main will gives us Address.
  2. sizeof will treat this address as “integer”.
  3. Size of Integer = 2 bytes (in Turbo C/C++ Compiler)
  4. Therefor output is 4.