1 votes 1 votes find the output of following program main() { extern int a; a=5; printf("%d",a); } Programming in C storage-classes-in-c + – someshawasthi asked Nov 30, 2022 someshawasthi 735 views answer comment Share Follow See all 4 Comments See all 4 4 Comments reply Pranavpurkar commented Nov 30, 2022 reply Follow Share error? a is not declared. 1 votes 1 votes rsansiya111 commented Nov 30, 2022 reply Follow Share Error >? 0 votes 0 votes someshawasthi commented Nov 30, 2022 reply Follow Share yes your ans is correct it is linker error but why it is error when I run the code on online turbo c compiler it print the value with no error can you please explain why?? 0 votes 0 votes Pranavpurkar commented Nov 30, 2022 reply Follow Share $a$ is declared as extern so its definition must be outside this function, but here no definition is present. And thus, when linker tries to link for the definition of $a$ outside of this function, and get linker error. 1 votes 1 votes Please log in or register to add a comment.
Best answer 1 votes 1 votes it will give error. because extern keyword is use for just for declaration of variable. it simply means variable’s definition is somewhere in code. that is why it give undefined reference error. deathWalker answered Nov 30, 2022 • selected Nov 30, 2022 by gatecse deathWalker comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes It will not give any compile time error but will give a runtime error (undefined symbol)! chokostar answered Nov 30, 2022 chokostar comment Share Follow See all 6 Comments See all 6 6 Comments reply gatecse commented Nov 30, 2022 reply Follow Share So is the image in above answer fake? 0 votes 0 votes chokostar commented Dec 1, 2022 reply Follow Share Tried it on gcc compiler on my linux machine too, it is giving this compile time error only. However gate considers turbo c and if turbo c gives no error, we have to go acc to that only! 0 votes 0 votes gatecse commented Dec 1, 2022 reply Follow Share GATE considers “Turbo C”? Thats the funniest thing I ever heard of GATE. Can you show me at least 1 previous year GATE question – however old it may be – where Turbo C was considered or even mentioned? In general GATE is a standard exam and current standards are always considered in GATE. This doesn’t mean students need to study the latest C standard etc, but if any answer changes if latest standard is applied (highly unlikely for GATE questions), the new answer will also get mark in GATE. But if you say “Turbo C” gave this answer they’ll just ignore it. 0 votes 0 votes chokostar commented Dec 1, 2022 reply Follow Share haha, I never said gate questions will explicitly mention “turbo c” , however I said that whenever such controversial output questions arise, gate generally complies with what turbo c gives as o/p. Again I am not making up things on my own, I am only writing what I have learnt from my mentor and needless to say, he is considered to be the god of algo! –1 votes –1 votes Psy Duck commented Dec 4, 2022 reply Follow Share Yes ….during compilation extern will say compiler “Tension nehi lene ka apun haina” 0 votes 0 votes gatecse commented Dec 4, 2022 reply Follow Share @chokostar Good luck to you and your god mentor 👎 0 votes 0 votes Please log in or register to add a comment.