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 2 of 6.
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.
Alekhya said:
1 decade ago
Please explain me why we should not use i?
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?
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.
Mounika said:
10 years ago
How can we rectify that?
@rti said:
1 decade ago
How can we know the program in 16 bit platform or on 32 bit platform?
Vikas said:
1 decade ago
please explain me, what is the mean of s*=3;
Vamsibhargavi said:
1 decade ago
Please explain in other way. I didn't get this.
MAX said:
1 decade ago
The extern should be written outside the main. Unless it will show declaration is not allowed error.
Sri said:
1 decade ago
For @Rehana question I think the answer is 10.
Because extern will access the value which is declared as a global. If wrong please explain me.
Because extern will access the value which is declared as a global. If wrong please explain me.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers