C Programming Questions and Answers on External Variables for Freshers

https://www.computersprofessor.com/2017/12/c-programming-questions-and-answers-on_4.html
1. What is the output of this 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
b) Compile time error
c) 0
d) Undefined
Answer: b
2. What is the output of this C code?
#include
int x;
void main()
{
printf("%d", x);
}
a) Junk value
b) Run time error
c) 0
d) Undefined
b) Run time error
c) 0
d) Undefined
Answer: c
3. What is the output of this 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
b) 3 3
c) 3 5
d) 3 4
Answer: d
4. What is the output of this 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
b) 3 4
c) 3 5
d) Run time error
Answer: a
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
6. Global variables are:
a) Internal
b) External
c) Both Internal and External
d) None of the mentioned
Answer: b
7. Which of the following are an external variable?
#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
b) b
c) c
d) d
Answer: d
8. What will be the output?
#include
int main()
{
printf("%d", d++);
}
int d = 10;
a) 9
b) 10
c) 11
d) Compile time error
b) 10
c) 11
d) Compile time error
Answer: d
9. What will be the output?
#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
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
10. What is the output of this C code?
#include
double i;
int main()
{
printf("%g\n",i);
return 0;
}
a) 0
b) 0.000000
c) Garbage value
d) Depends on the compiler
b) 0.000000
c) Garbage value
d) Depends on the compiler
Answer: a
11. Which part of the program address space is p stored in the code given below?
#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
b) Data segment
c) Bss segment
d) Stack
Answer: b
12. Which part of the program address space is p stored in the code given below?
#include
int *p;
int main()
{
int i = 0;
p = &i;
return 0;
}
a) Code/text segment
b) Data segment
c) Bss segment
d) Stack
b) Data segment
c) Bss segment
d) Stack
Answer: c
13. Can variable i be accessed by functions in another source file?
#include
int i;
int main()
{
printf("%d\n", i);
}
a) 0
b) false
c) Only if static keyword is used
d) Depends on the type of the variable
b) false
c) Only if static keyword is used
d) Depends on the type of the variable
Answer: a
14. Property of external variable to be accessed by any source file is called by C90 standard as
a) external linkage
b) external scope
c) global scope
d) global linkage
Answer: a
15. What is the output of this C code?
#include
int *i;
int main()
{
if (i == NULL)
printf("true\n");
return 0;
}
a) true
b) true only if NULL value is 0
c) Compile time error
d) Nothing
b) true only if NULL value is 0
c) Compile time error
d) Nothing
Answer: a
16. What is the output of this C code?
#include
int *i;
int main()
{
if (i == 0)
printf("true\n");
return 0;
}
a) true
b) true only if NULL value is 0
c) Compile time error
d) Nothing
b) true only if NULL value is 0
c) Compile time error
d) Nothing
Answer: b
17. What is the output of this 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
b) 4
c) 5
d) 0
Answer: a