Linked Questions

Popular Questions

Memory allocation after declaration of extern class variable

Asked by At

I have read in multiple places that when declaring an extern variable, the memory is not designated until the definition is made. I was trying this code which is giving contradictory output in gcc.

#include <stdio.h>

int main() {
    extern int a;
    printf("%lu", sizeof(a));
    return 0;
}

it should have shown error or zero size. but the output was following. please justify the output. Is it example of another undefined behavior?

[email protected]:~$ ./a
4

Related Questions