Here is a listing of basic C Objective Questions on “External Variable” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include -
double i;
-
int main()
-
{ -
printf("%gn",i);
-
return 0;
-
}
a) 0
b) 0.000000
c) Garbage value
d) Depends on the compiler
Answer: a
Clarification: None.
2. Which part of the program address space is p stored in the following C code?
-
#include -
int *p = NULL;
-
int main()
-
{ -
int i = 0;
-
p = &i;
-
return 0;
-
}
a) Code/text segment
b) Data segment
c) Bss segment
d) Stack
Answer: b
Clarification: None.
3. Which part of the program address space is p stored in the following C code?
-
#include -
int *p;
-
int main()
-
{ -
int i = 0;
-
p = &i;
-
return 0;
-
}
a) Code/text segment
b) Data segment
c) Bss segment
d) Stack
Answer: c
Clarification: None.
4. Can variable i be accessed by functions in another source file?
-
#include -
int i;
-
int main()
-
{ -
printf("%dn", i);
-
}
a) Yes
b) No
c) Only if static keyword is used
d) Depends on the type of the variable
Answer: a
Clarification: None.
5. Property of the external variable to be accessed by any source file is called by the C90 standard as __________
a) external linkage
b) external scope
c) global scope
d) global linkage
Answer: a
Clarification: None.
6. What will be the output of the following C code?
-
#include -
int *i;
-
int main()
-
{ -
if (i == NULL)
-
printf("truen");
-
return 0;
-
}
a) true
b) true only if NULL value is 0
c) Compile time error
d) Nothing
Answer: a
Clarification: None.
7. What will be the output of the following C code?
-
#include -
int *i;
-
int main()
-
{ -
if (i == 0)
-
printf("truen");
-
return 0;
-
}
a) true
b) true only if NULL value is 0
c) Compile time error
d) Nothing
Answer: b
Clarification: None.
8. What will be the output of the following C code?
-
#include -
static int x = 5;
-
void main()
-
{ -
x = 9;
-
{ -
int x = 4;
-
} -
printf("%d", x);
-
}
a) 9
b) 4
c) 5
d) 0
Answer: a
Clarification: None.
