250+ TOP MCQs on Scope of a Variable and Answers

basic C questions on “Scope of a Variable”. One shall practice these basic Objective Questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C Objective Questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of basic C questions on “Scope of a Variable” along with answers, explanations and/or solutions:

1. What will be the sequence of allocation and deletion of variables in the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int a;
  5.         {
  6.             int b;
  7.         }
  8.     }

a) a->b, a->b
b) a->b, b->a
c) b->a, a->b
d) b->a, b->a
Answer: b
Clarification: None.

2. Array sizes are optional during array declaration by using ______ keyword.
a) auto
b) static
c) extern
d) register
Answer: c
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         int x = 3;
  5.         {
  6.             x = 4;
  7.             printf("%d", x);
  8.         }
  9.     }

a) 4
b) 3
c) 0
d) Undefined
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int x = 5;
  3.     void main()
  4.     {
  5.         int x = 3;
  6.         m();
  7.         printf("%d", x);
  8.     }
  9.     void m()
  10.     {
  11.         x = 8;
  12.         n();
  13.     }
  14.     void n()
  15.     {
  16.         printf("%d", x);
  17.     }

a) 8 3
b) 3 8
c) 8 5
d) 5 3
Answer: a
Clarification: None.

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

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

a) 0
b) 4
c) Compile time error
d) Undefined
Answer: b
Clarification: None.

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

  1.     #include 
  2.     static int x = 5;
  3.     void main()
  4.     {
  5.         int x = 9;
  6.         {
  7.             x = 4;
  8.         }
  9.         printf("%d", x);
  10.     }

a) 9
b) 5
c) 4
d) 0
Answer: c
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         {
  5.             int x = 8;
  6.         }
  7.         printf("%d", x);
  8.     }

a) 8
b) 0
c) Undefined
d) Compile time error
Answer: d
Clarification: None.

Leave a Reply

Your email address will not be published. Required fields are marked *