1 votes 1 votes how it is compiler error int main() { extern int i; printf("%d ", i); { int i = 10; printf("%d ", i); } } (a) 0 10 (b) Compiler Error (c) 0 0 (d) 10 10 ans b tiger asked Nov 29, 2015 tiger 5.1k views answer comment Share Follow See 1 comment See all 1 1 comment reply varunshankara commented Oct 29, 2023 reply Follow Share Hi, If I correctly understand the question here, “how it is compiler error”. the options provided here are wrong. error is @ line 2, extern int i; definition for the same is not present. error: undefined reference to i. and it will be an linker error. Answers will be: as we know extern variable tells compiler that definition for the declared variable present out side of my scope/ some where else out side this file. it is the responsibility of the linker to find the link for the same. Here two assumptions can be made. Definition of the variable “int i” is present out side the file, present inside the project. By considering it there will be no compilation error. Output will be option A. 0 10. If definition for extern variable is not defined in any of the file in the project. By considering it, there will be an Linker error, “undefined reference to i”, not compiler error. 0 votes 0 votes Please log in or register to add a comment.
1 votes 1 votes int main(){extern int i;printf("%d ", i);{ // what is this thats y compiler error.int i = 10;printf("%d ", i);}} Prashant. answered Nov 29, 2015 Prashant. comment Share Follow See all 2 Comments See all 2 2 Comments reply tiger commented Nov 29, 2015 reply Follow Share not getting friend? 0 votes 0 votes nadeshseen commented Sep 10, 2019 reply Follow Share @Prashant. that is the starting of a block. where you have written the comment there is no error. the error is due to extern. It means i is just declared not defined. 0 votes 0 votes Please log in or register to add a comment.
1 votes 1 votes http://www.geeksforgeeks.org/understanding-extern-keyword-in-c/ first understand the extern keyword int main(){extern int i;// here compiler has expecting that 'i' is already defined in some file but is has not defined thats why we are getting compiler Errorprintf("%d ", i);{int i = 10;printf("%d ", i);}} answer is option B Sandip Shaw answered Nov 29, 2015 Sandip Shaw comment Share Follow See all 2 Comments See all 2 2 Comments reply admin commented Nov 29, 2015 reply Follow Share That should be link error rt? 0 votes 0 votes Sandip Shaw commented Nov 29, 2015 reply Follow Share yes it should be linker error but according to option i have chosen the answer 1 votes 1 votes Please log in or register to add a comment.
0 votes 0 votes option B is correct as extern is declared but ther is no declaration of variable i. adhi_1897 answered Mar 9, 2022 adhi_1897 comment Share Follow See all 0 reply Please log in or register to add a comment.