0 votes 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 asked Nov 10, 2018 edited Nov 10, 2018 by Mk Utkarsh Mk Utkarsh 579 views answer comment Share Follow See all 9 Comments See all 9 9 Comments reply Hemanth_13 commented Nov 10, 2018 reply Follow Share It should give an error because you are saying the variable is constant and then you are confusing it by saying volatile 0 votes 0 votes Mk Utkarsh commented Nov 10, 2018 reply Follow Share 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 votes 0 votes Shubhgupta commented Nov 10, 2018 reply Follow Share 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 votes 0 votes Mk Utkarsh commented Nov 10, 2018 reply Follow Share Shubhgupta which will cause multiple declaration error? 0 votes 0 votes Shubhgupta commented Nov 10, 2018 reply Follow Share which you mentioned in question not your comment one.. :) 0 votes 0 votes Mk Utkarsh commented Nov 10, 2018 reply Follow Share 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 votes 0 votes Shubhgupta commented Nov 10, 2018 reply Follow Share yes correction is needed for that question. 0 votes 0 votes Somoshree Datta 5 commented Nov 16, 2018 reply Follow Share 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 votes 1 votes Mk Utkarsh commented Nov 16, 2018 reply Follow Share Somoshree Datta 5 i also believe the same 0 votes 0 votes Please log in or register to add a comment.