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.
@rti said:
1 decade ago
How can we know the program in 16 bit platform or on 32 bit platform?
Sujithra said:
1 decade ago
Why we use sizeof() what purpose to use?
Anay said:
1 decade ago
@Vikas.
This is discussion forum for extern you should ask your question at appropriate place.
By the way s*=3 means s=s*3.
This is discussion forum for extern you should ask your question at appropriate place.
By the way s*=3 means s=s*3.
Jeeva said:
1 decade ago
How to access the variable which is declare in another program.
Using the extern is there any example.
Here the variable i is declared and defined in the same program then whats the usage of extern here?
Using the extern is there any example.
Here the variable i is declared and defined in the same program then whats the usage of extern here?
Alekhya said:
1 decade ago
Please explain me why we should not use i?
Anitha said:
1 decade ago
enum means if we declare the value to only one variable when we execute the program it takes the next value to another variables.
For ex:
enum var{var1='a',var2,var3};
When we type the line in program it produce the following output:
a b c
This is a process of enum.
But the given qus i value was initialized hadn't any data types so it displays the linking error.
For ex:
enum var{var1='a',var2,var3};
When we type the line in program it produce the following output:
a b c
This is a process of enum.
But the given qus i value was initialized hadn't any data types so it displays the linking error.
Nandhu said:
1 decade ago
Can someone briefly explain me about linkin error and enum with eg ?
Alexandru said:
1 decade ago
Guys, I don't know how turbo C on 16 bit platform worked, but I know this should show 2, not error. Also, if this this should trigger an error, then you should provide the compilation or linkage line. Try this on any decent compiler like gcc and then fix the question.
Batman said:
1 decade ago
i is already defined how can it be said that it is not defined?
Archana rajawat said:
1 decade ago
extern int i means global variable that means it can move anywhere. So it has to print the size of i. If I am wrong then explain that.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers