Why applying sizeof operator to an extern variable does not output 0

  • A+

The output of the following code is 4. Shouldn't it be 0?

Since a is declared and not been defined and hence memory is not allocated for it.

#include <stdio.h> #include <stdlib.h>  int main() {     extern int a;     printf("%ld",sizeof(a));      return 0; } 


We know what the size of a is even if it is not defined in this module. sizeof does not tell you how much memory has been allocated for an object in this module. It tells you how much memory the object requires.


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: