C Tests

Best Reference Books

C Programming Questions and Answers – Static Variables – 1

Sanfoundry’s 1000+ MCQs on C helps anyone preparing for placement in Oracle and other companies. Anyone looking for Oracle placement papers should practice these 1000+ questions continuously for 2-3 months, thereby ensuring a top position in placements.

Here is a listing of C questions and puzzles on “Static Variables” along with answers, explanations and/or solutions:

1. What will be the output of the following C code?

advertisement

#include <stdio.h>

void main()

{

m();

m();

}

void m()

{

staticint x =5;

x++;

printf("%d", x);

}

a) 6 7
b) 6 6
c) 5 5
d) 5 6View Answer

Answer: a
Explanation: None.

2. What will be the output of the following C code?

#include <stdio.h>

void main()

{

staticint x;

printf("x is %d", x);

}

a) 0
b) 1
c) Junk value
d) Run time errorView Answer

Answer: a
Explanation: None.

advertisement

3. What will be the output of the following C code?

#include <stdio.h>

staticint x;

void main()

{

int x;

printf("x is %d", x);

}

a) 0
b) Junkvalue
c) Run time error
d) NothingView Answer

Answer: b
Explanation: None.

4. What will be the output of the following C code?

#include <stdio.h>

void main()

{

staticdouble x;

int x;

printf("x is %d", x);

}

a) Nothing
b) 0
c) Compile time error
d) JunkvalueView Answer

Answer: c
Explanation: None.

advertisement

5. What will be the output of the following C code?

#include <stdio.h>

void main()

{

staticint x;

if(x++<2)

main();

}

a) Infinite calls to main
b) Run time error
c) Varies
d) main is called twiceView Answer

Answer: d
Explanation: None.

6. 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 mentionedView Answer

Answer: c
Explanation: None.

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