C Questions and Answers Part-24

1. What will be the output of the following C code?
#include < stdio.h >
void main()
{
{
int x = 8;
}
printf("%d", x);
}
a) 8
b) 0
c) Undefined
d) Compile time error

Answer: d

2. What will be the output of the following C code?
#include < stdio.h >
void main()
{
m();
m();
}
void m()
{
static int x = 5;
x++;
printf("%d", x);
}
a) 6 7
b) 6 6
c) 5 5
d) 5 6

Answer: a

3. What will be the output of the following C code?
#include < stdio.h >
void main()
{
static int x;
printf("x is %d", x);
}
a) 0
b) 1
c) Junk value
d) Run time error

Answer: a

4. What will be the output of the following C code?
#include < stdio.h >
static int x;
void main()
{
int x;
printf("x is %d", x);
}
a) 0
b) Junkvalue
c) Run time error
d) Nothing

Answer: b

5. What will be the output of the following C code?
#include < stdio.h >
void main()
{
static double x;
int x;
printf("x is %d", x);
}
a) Nothing
b) 0
c) Compile time error
d) Junkvalue

Answer: c

6. What will be the output of the following C code?
#include < stdio.h >
void main()
{
static int x;
if (x++ < 2)
main();
}
a) Infinite calls to main
b) Run time error
c) Varies
d) main is called twice

Answer: d

7. Which of following is not accepted in C?
a) static a = 10; //static as
b) static int func (int); //parameter as static
c) static static int a; //a static variable prefixed with static
d) all of the mentioned

Answer: c

8. Which of the following cannot be static in C?
a) Variables
b) Functions
c) Structures
d) None of the mentioned

Answer: d

9. Functions have static qualifier for its declaration by default.
a) true
b) false
c) Depends on the compiler
d) Depends on the standard

Answer: b

10. Is initialisation mandatory for local static variables?
a) yes
b) no
c) Depends on the compiler
d) Depends on the standard

Answer: b