0 0 votes https://gateoverflow.in/45555/c-programming-predict-the-output main() { { extern int i; int i=20; { const volatile unsigned i=30; printf("%d",i); } printf("%d",i); } printf("%d",i); } int i; rude explained how output is printed but its giving error when i'm trying to run the program here https://ideone.com/xteXgV Programming in C programming-in-c output + – Mk Utkarsh 1.4k views answer comment Share Follow Print See all 9 Comments 9 9 Comments reply Hemanth_13 commented Nov 10, 2018 reply Follow flag It should give an error because you are saying the variable is constant and then you are confusing it by saying volatile 0 0 replyShare Mk Utkarsh commented Nov 10, 2018 reply Follow flag according to me code is wrong because extern int i; // i is declared Then again in next line int i=20; /* defined i but it is treated as local variable because there was no declaration of y globally with extern */ extern int i; main() { { int i=20; { const volatile unsigned i=30; printf("%d",i); } printf("%d",i); } printf("%d",i); } int i; https://ideone.com/TxkXNu The above modified code will work fine and print 30200 0 0 replyShare Shubhgupta commented Nov 10, 2018 reply Follow flag I think this will cause multiple declaration error even if you run the code with "extern int i" inside main then it will work fine. 0 0 replyShare Mk Utkarsh commented Nov 10, 2018 reply Follow flag Shubhgupta which will cause multiple declaration error? 0 0 replyShare Shubhgupta commented Nov 10, 2018 reply Follow flag which you mentioned in question not your comment one.. :) 0 0 replyShare Mk Utkarsh commented Nov 10, 2018 reply Follow flag Shubhgupta yes so the selected answer on that question needs correction right? unfortunately not many people commented here for confirmation that's why i'm unable to deselect that answer 0 0 replyShare Shubhgupta commented Nov 10, 2018 reply Follow flag yes correction is needed for that question. 0 0 replyShare Somoshree Datta 5 commented Nov 16, 2018 reply Follow flag Mk Utkarsh When we declare a variable as extern, its a promise to the compiler that the definition of that variable will be at some other place in global scope and not in the same block in which the variable is declared as extern. So when u try to define the variable in the same block in which it is declared, it will result in compile time error as its a local variable and it wont fulfill the promise made to the compiler since local variables are invisible to linkers. Am i correct? 1 1 replyShare Mk Utkarsh commented Nov 16, 2018 reply Follow flag Somoshree Datta 5 i also believe the same 0 0 replyShare Please log in or register to add a comment.