C Programming Questions and Answers – External Variables
C Programming Questions and Answers – External Variables
1.What is the output of this C code?
#include <stdio.h>
void main()
{
m();
printf(“%d”, x);
}
int x;
void m()
{
x = 4;
}
a) 4
b) Compile time error
c) 0
d) Undefined
View Answer
2.What is the output of this C code?
#include <stdio.h>
int x;
void main()
{
printf(“%d”, x);
}
a) Junk value
b) Run time error
c) 0
d) Undefined
View Answer
3.What is the output of this C code?
#include <stdio.h>
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
View Answer
4.What is the output of this C code?
#include <stdio.h>
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
View Answer
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
View Answer
6.Global variables are:
a) Internal
b) External
c) Both (a) and (b)
d) None of the mentioned
View Answer
7.Which of the following are an external variable?
#include <stdio.h>
int func (int a)
{
int b;
return b;
}
int main()
{
int c;
func (c);
}
int d;
a) a
b) b
c) c
d) d
View Answer
8.What will be the output?
#include <stdio.h>
int main()
{
printf(“%d”, d++);
}
int d = 10;
a) 9
b) 10
c) 11
d) Compile time error
View Answer
9.What will be the output?
#include <stdio.h>
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
View Answer
10.What is the output of this C code?
#include <stdio.h>
double i;
int main()
{
printf(“%g\n”,i);
return 0;
}
a) 0
b) 0.000000
c) Garbage value
d) Depends on the compiler
View Answer
11.Which part of the program address space is p stored in the code given below?
#include <stdio.h>
int *p = NULL;
int main()
{
int i = 0;
p = &i;
return 0;
}
a) Code/text segment
b) Data segment
c) Bss segment
d) Stack
View Answer
12.Which part of the program address space is p stored in the code given below?
#include <stdio.h>
int *p;
int main()
{
int i = 0;
p = &i;
return 0;
}
a) Code/text segment
b) Data segment
c) Bss segment
d) Stack
View Answer
13.Can variable i be accessed by functions in another source file?
#include <stdio.h>
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
View Answer
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
View Answer
15.What is the output of this C code?
#include <stdio.h>
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
View Answer
16.What is the output of this C code?
#include <stdio.h>
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
View Answer
17.What is the output of this C code?
#include <stdio.h>
static int x = 5;
void main()
{
x = 9;
{
int x = 4;
}
printf(“%d”, x);
}
a) 9
b) 4
c) 5
d) 0