Log In Register

Units


Static Variables - Questions and Answers

 

Practice these Static Variables  under C Programming walk-in interview Questions/ examination questions with best tricks and short cuts with solution. Student (candidate) who want to crack the walk in interview, competitive exams and want to find short cuts and tricks to solve questions on Static Variables for following purpose.


– Anyone who is wishing to increase their perfect knowledge of Static Variables of C Programming.
– Anyone who is preparing for aptitude test and increase his in depth aptitude knowledge C Programming specifically  Static Variables .
– Anyone who is preparing for interviews (competitive examinations, govt examinations and bank examinations, off-campus or on campus interviews, walk-in interview and company interviews) having questions on Static Variables under C Programming.

– Anyone who is preparing for aptitude test or competitive exam or entrance exam.
– Anyone who is preparing for entrance examinations and other competitive examinations.
– All Experienced, Freshers and Students.

Here is list of Questions and Answers covering all key area of   Static Variables topic of C Programming:

 

1.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         m();
  5.         m();
  6.     }
  7.     void m()
  8.     {
  9.         static int x = 5;
  10.         x++;
  11.         printf("%d", x);
  12.     }

Answer: Option D

Explanation:

2.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         static int x;
  5.         printf("x is %d", x);
  6.     }

Answer: Option B

Explanation:

3.

Which of the following is true for static variable?

Answer: Option A

Explanation:

4.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         foo();
  5.         foo();
  6.     }
  7.     void foo()
  8.     {
  9.         int i = 11;
  10.         printf("%d ", i);
  11.         static int j = 12;
  12.         j = j + 1;
  13.         printf("%d\n", j);
  14.     }

Answer: Option D

Explanation:

5.

Assignment statements assigning value to local static variables are executed only once

Answer: Option C

Explanation:

6.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         static int x;
  5.         if (x++ < 2)
  6.         main();
  7.     }

Answer: Option A

Explanation:

7.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     static int x;
  3.     void main()
  4.     {
  5.         int x;
  6.         printf("x is %d", x);
  7.     }

Answer: Option C

Explanation:

8.

Is initialisation mandatory for local static variables?

Answer: Option C

Explanation:

9.

What is the output of code given below if these two files are linked and run?
in file test.c

  1.     #include <stdio.h>
  2.     #include "test.h"
  3.     int main()
  4.     {
  5.         i = 10;
  6.         printf("%d ", i);
  7.         foo();
  8.     }
  9. 
     
  10.     in file test1.c
  11.     #include <stdio.h>
  12.     #include "test.h"
  13.     int foo()
  14.     {
  15.         printf("%d\n", i);
  16.     }
  17. 
     
  18.     in file test.h
  19.     #include <stdio.h>
  20.     #include <stdlib.h>
  21.     static int i;

Answer: Option D

Explanation:

10.

Functions have static qualifier for its declaration by default.

Answer: Option C

Explanation:

11.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         static double x;
  5.         int x;
  6.         printf("x is %d", x);
  7.     }

Answer: Option B

Explanation:

12.

Which of following is not accepted in C?

Answer: Option B

Explanation:

13.

Which of the following cannot be static in C?

Answer: Option D

Explanation:

14.

What is the format identifier for “static a = 20.5;”?

Answer: Option C

Explanation:

15.

Comment on the output of this C code?

  1.     #include <stdio.h>
  2.     void func();
  3.     int main()
  4.     {
  5.         static int b = 20;
  6.         func();
  7.     }
  8.     void func()
  9.     {
  10.         static int b;
  11.         printf("%d", b);
  12.     }

Answer: Option D

Explanation: