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;
}
2
4
vary from compiler
Linker Error : Undefined symbol 'i'
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.
Discussion:
57 comments Page 3 of 6.

Ranjani said:   1 decade ago
Even though variable i in external file it is int data type. In sizeof() operator it going to print size of the datatype only. the data type mentioned in (extern int i;) statement. Then why we didn't get the output?

Shankar said:   10 years ago
I would like to know the exact difference between C, C++ and Java.

Uma said:   9 years ago
Please tell me the output of the program in detail.

#include
int main()
{
extern int i;i=20;
printf("%d\n",i);
return 0;
}

Sai lakshmi said:   9 years ago
What is extern variable, how it work? please explain!

Lakshay said:   8 years ago
int i=20; is this statement a declaration or definition?

Explain in detail.

Prbaraj said:   8 years ago
Here, int i=20; is the definition.

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?

Sankar said:   8 years ago
When i am running like this no error is showing. why?

#include<stdio.h>
int main()
{
extern int i;
printf("%d\n", sizeof(i));
return 0;
}
i = 20;

Tedy said:   4 months ago
2 bytes is output according to programming code gives. And defined correction in correct and unsigned, signed int or long or short is correct.

But defined object is seen as interger and it 20=I is correct declared, so integer declared but written in outer side on scope.

Rehana said:   1 decade ago
#include<stdio.h>
int main()
{
extern int i;
i = 20;
printf("%d\n", sizeof(i));
return 0;
}
int i=10

The output will be 10 or 20?


Post your comments here:

Your comments will be displayed after verification.