C Programming - Declarations and Initializations - Discussion
Discussion Forum : Declarations and Initializations - Find Output of Program (Q.No. 2)
2.
What will be the output of the program in 16 bit platform (Turbo C under DOS)?
#include<stdio.h>
int main()
{
extern int i;
i = 20;
printf("%d\n", sizeof(i));
return 0;
}
Answer: Option
Explanation:
Linker Error : Undefined symbol 'i'
The statement extern int i specifies to the compiler that the memory for 'i' is allocated in some other program and that address will be given to the current program at the time of linking. But linker finds that no other variable of name 'i' is available in any other program with memory space allocated for it. Hence a linker error has occurred.
The statement extern int i specifies to the compiler that the memory for 'i' is allocated in some other program and that address will be given to the current program at the time of linking. But linker finds that no other variable of name 'i' is available in any other program with memory space allocated for it. Hence a linker error has occurred.
Discussion:
57 comments Page 4 of 6.
Kavitha said:
1 decade ago
The 'extern int i' the use of extern means it is outside value. In this above question why 'i' is not specified ?
MAX said:
1 decade ago
The extern should be written outside the main. Unless it will show declaration is not allowed error.
Nnn said:
1 decade ago
How would we know that there is sme I in other program or not. So (C) is d answer. Ths is my doubt.
Amulya said:
8 years ago
Would you please explain why we get an error?
Is it because we have not kept single code for i?
Is it because we have not kept single code for i?
Nani said:
1 decade ago
If we declare int i=20 out side the main, then the ans is 2, but I got 4 why? that's possible.
Lakshay said:
8 years ago
int i=20; is this statement a declaration or definition?
Explain in detail.
Explain in detail.
Sharda said:
1 decade ago
Explain in detail about external variables. Whatr is the need of using them?
@rti said:
1 decade ago
How can we know the program in 16 bit platform or on 32 bit platform?
Pallavi said:
1 decade ago
We have already declared the int i=20 then why it gives linker error?
Nandhu said:
1 decade ago
Can someone briefly explain me about linkin error and enum with eg ?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers