C Programming Questions and Answers on External Variables for Freshers

1. What is the output of this C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         m();
  5.         printf("%d", x);
  6.     }
  7.     int x;
  8.     void m()
  9.     {
  10.         x = 4;
  11.     }
a) 4
b) Compile time error
c) 0
d) Undefined
Answer: b
2. What is the output of this C code?

  1.     #include 
  2.     int x;
  3.     void main()
  4.     {
  5.         printf("%d", x);
  6.     }
a) Junk value
b) Run time error
c) 0
d) Undefined
Answer: c
3. What is the output of this C code?

  1.     #include 
  2.     int x = 5;
  3.     void main()
  4.     {
  5.         int x = 3;
  6.         printf("%d", x);
  7.         {
  8.             x = 4;
  9.         }
  10.         printf("%d", x);
  11.     }
a) Run time error
b) 3 3
c) 3 5
d) 3 4
Answer: d
4. What is the output of this C code?

  1.     #include 
  2.     int x = 5;
  3.     void main()
  4.     {
  5.         int x = 3;
  6.         printf("%d", x);
  7.         {
  8.             int x = 4;
  9.         }
  10.         printf("%d", x);
  11.     }
a) 3 3
b) 3 4
c) 3 5
d) Run time error
Answer: a
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
Answer: b
6. Global variables are:

a) Internal
b) External
c) Both Internal and External
d) None of the mentioned
Answer: b
7. Which of the following are an external variable?

  1.     #include 
  2.     int func (int a)
  3.     {
  4.         int b;
  5.         return b;
  6.     }
  7.     int main()
  8.     {
  9.         int c;
  10.         func (c);
  11.     }
  12.     int d;
a) a
b) b
c) c
d) d
Answer: d
8. What will be the output?

  1.     #include 
  2.     int main()
  3.     {
  4.         printf("%d", d++);
  5.     }
  6.     int d = 10;
a) 9
b) 10
c) 11
d) Compile time error
Answer: d
9. What will be the output?

  1.     #include 
  2.     double var = 8;
  3.     int main()
  4.     {
  5.         int var = 5;
  6.         printf("%d", var);
  7.     }
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
Answer: a
10. What is the output of this C code?

  1.     #include 
  2.     double i;
  3.     int main()
  4.     {
  5.        printf("%g\n",i);
  6.        return 0;
  7.     }
a) 0
b) 0.000000
c) Garbage value
d) Depends on the compiler
Answer: a
11. Which part of the program address space is p stored in the code given below?

  1.     #include 
  2.     int *p = NULL;
  3.     int main()
  4.     {
  5.         int i = 0;
  6.         p = &i;
  7.         return 0;
  8.     }
a) Code/text segment
b) Data segment
c) Bss segment
d) Stack
Answer: b
12. Which part of the program address space is p stored in the code given below?

  1.     #include 
  2.     int *p;
  3.     int main()
  4.     {
  5.         int i = 0;
  6.         p = &i;
  7.         return 0;
  8.     }
a) Code/text segment
b) Data segment
c) Bss segment
d) Stack
Answer: c
13. Can variable i be accessed by functions in another source file?

  1.     #include 
  2.     int i;
  3.     int main()
  4.     {
  5.         printf("%d\n", i);
  6.     }
a) 0
b) false
c) Only if static keyword is used
d) Depends on the type of the variable
Answer: a
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
Answer: a
15. What is the output of this C code?

  1.     #include 
  2.     int *i;
  3.     int main()
  4.     {
  5.         if (i == NULL)
  6.             printf("true\n");
  7.         return 0;
  8.     }
a) true
b) true only if NULL value is 0
c) Compile time error
d) Nothing
Answer: a
16. What is the output of this C code?

  1.     #include 
  2.     int *i;
  3.     int main()
  4.     {
  5.         if (i == 0)
  6.             printf("true\n");
  7.         return 0;
  8.     }
a) true
b) true only if NULL value is 0
c) Compile time error
d) Nothing
Answer: b
17. What is the output of this C code?

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

Related

Data Structures Multiple choice Questions and Answers on Doubly Linked List

1. Which of the following is false about a doubly linked list? a) We can navigate in both the directionsb) It requires more space than a singly linked listc) The insertion and deletion of a node ta...

Data Structures Multiple Choice Questions and Answers on Stack using Linked List

1. What is the complexity of searching for a particular element in a Singly Linked List? a) O(n)b) O(1)c) lognd) nlogn Answer: a Explanation: Singly Linked List allows you to traverse in one dire...

Data Structures Multiple Choice Questions and Answers on Circular Linked List

1. What differentiates a circular linked list from a normal linked list? a) You cannot have the ‘next’ pointer point to null in a circular linked listb) It is faster to traverse the circular linked...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item