Home » C Programming » Variables » Question
  1. Which of the following is the correct output for the program given below?
    #include <studio.h>
    int main()
    {
    extern int k;
    printf("%d\n", k );
    return 0;
    }
    int k = 30;
    1. 30
    2. 0
    3. Garbage value
    4. Error
Correct Option: A

No error, When we use extern keyword with uninitialized variable compiler think variable has initialized somewhere else in the program while when we don't use extern keyword then compiler initialized it with default value.

So output is 30.



Your comments will be displayed only after manual approval.