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.

Nandhu said:   1 decade ago
Can someone briefly explain me about linkin error and enum with eg ?

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.

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?

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.

Sujithra said:   1 decade ago
Why we use sizeof() what purpose to use?

@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;

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?

Noor said:   1 decade ago
Global declaration is meant for accessing variable even outside the block where it's declared, but that doesn't mean that it cannot be accessed or defined in the block where it is declared, so we should not get any error.


Post your comments here:

Your comments will be displayed after verification.