1 votes 1 votes #include <stdio.h> int i =20; int main() { int i = 10; extern int i; printf("%d",i); } Why does this program give Compiler error?? please explain Programming in C programming-in-c compilation-error extern-variable + – Thor-o-s asked Aug 24, 2022 retagged Sep 17, 2023 by Hira Thakur Thor-o-s 749 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
Best answer 4 votes 4 votes Yes this program should give compiler error because [ Jiren ] answered Aug 24, 2022 selected Aug 25, 2022 by Thor-o-s [ Jiren ] comment Share Follow See all 4 Comments See all 4 4 Comments reply Arjun commented Aug 24, 2022 reply Follow Share Are you saying that if we remove printf call then there will be no error? 0 votes 0 votes [ Jiren ] commented Aug 24, 2022 reply Follow Share @Arjun sir what i wanted to say is there is a conflict between the two variables of same namesit is same as defining two variables with same names like #include <stdio.h>int main(){ int b = 20; int b = 30; return 0;}which results in compiler error 1 votes 1 votes Arjun commented Aug 24, 2022 reply Follow Share :) That’s not what you have written. And is the issue with defining a variable multiple times or declaring a variable multiple times? 0 votes 0 votes [ Jiren ] commented Aug 24, 2022 reply Follow Share @Arjun ok sir i will change the answer and will write in detail 😅 i think the issue is with defining of a variable multiple times my reasoning is if we declare a variable we are just saying to the compiler that there is a so and so variable ( we can use extern int i many times without any issue ) but while defining we need to allocate memory this is where things go crazy ( compiler will be like : i already allocated memory for this dude why am i seeing him again in the line 😋 ) 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes Before the Int Main() datatype and variable declared Kushal Kumar answered Sep 23, 2022 Kushal Kumar comment Share Follow See all 0 reply Please log in or register to add a comment.