Here is a listing of C questions and puzzles on “External Variables” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
m();
-
printf("%d", x);
-
}
-
int x;
-
void m()
-
{
-
x = 4;
-
}
a) 4
b) Compile time error
c) 0
d) Undefined
Answer: b
Clarification: None.
2. What will be the output of the following C code?
-
#include
-
int x;
-
void main()
-
{
-
printf("%d", x);
-
}
a) Junk value
b) Run time error
c) 0
d) Undefined
Answer: c
Clarification: None.
3. What will be the output of the following C code?
-
#include
-
int x = 5;
-
void main()
-
{
-
int x = 3;
-
printf("%d", x);
-
{
-
x = 4;
-
}
-
printf("%d", x);
-
}
a) Run time error
b) 3 3
c) 3 5
d) 3 4
Answer: d
Clarification: None.
4. What will be the output of the following C code?
-
#include
-
int x = 5;
-
void main()
-
{
-
int x = 3;
-
printf("%d", x);
-
{
-
int x = 4;
-
}
-
printf("%d", x);
-
}
a) 3 3
b) 3 4
c) 3 5
d) Run time error
Answer: a
Clarification: None.
5. Functions in C are always _________
a) Internal
b) External
c) Both Internal and External
d) External and Internal are not valid terms for functions
Answer: b
Clarification: None.
6. Global variables are ____________
a) Internal
b) External
c) Both Internal and External
d) None of the mentioned
Answer: b
Clarification: None.
7. Which of the following is an external variable in the following C code?
-
#include
-
int func (int a)
-
{
-
int b;
-
return b;
-
}
-
int main()
-
{
-
int c;
-
func (c);
-
}
-
int d;
a) a
b) b
c) c
d) d
Answer: d
Clarification: None.
8. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
printf("%d", d++);
-
}
-
int d = 10;
a) 9
b) 10
c) 11
d) Compile time error
Answer: d
Clarification: None.
9. What will be the output of the following C code?
-
#include
-
double var = 8;
-
int main()
-
{
-
int var = 5;
-
printf("%d", var);
-
}
a) 5
b) 8
c) Compile time error due to wrong format identifier for double
d) Compile time error due to redeclaration of variable with same name
Answer: a
Clarification: None.