C Programming Questions and Answers on Register Variables for Freshers

1. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         register int i = 10;
  5.         int *p = &i;
  6.         *p = 11;
  7.         printf("%d %d\n", i, *p);
  8.     }
a) Depends on whether i is actually stored in machine register
b) 10 10
c) 11 11
d) Compile time error
Answer: d
2. register keyword mandates compiler to place it in machine register.

a) true
b) false
c) Depends on the standard
d) None of the mentioned
Answer: b
3. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         register static int i = 10;
  5.         i = 11;
  6.         printf("%d\n", i);
  7.     }
a) 10
b) Compile time error
c) Undefined behaviour
d) 11
Answer: b
4. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         register auto int i = 10;
  5.         i = 11;
  6.         printf("%d\n", i);
  7.     }
a) 10
b) Compile time error
c) Undefined behaviour
d) 11
Answer: b
5. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         register const int i = 10;
  5.         i = 11;
  6.         printf("%d\n", i);
  7.     }
a) 10
b) Compile time error
c) Undefined behaviour
d) 11
Answer: b
6. Register storage class can be specified to global variables

a) true
b) false
c) Depends on the compiler
d) Depends on the standard
Answer: b
7. Which among the following is wrong for “register int a;” ?

a) Compiler generally ignores the request.
b) You cannot take the address of this variable
c) Access time to a is critical
d) None of the mentioned
Answer: d
8. What is the output of this C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         register int x = 5;
  5.         m();
  6.         printf("x is %d", x);
  7.     }
  8.     void m()
  9.     {
  10.         x++;
  11.     }
a) 6
b) 5
c) Junk value
d) Compile time error
Answer: d
9. When compiler accepts the request to use the variable as a register?

a) It is stored in CPU
b) It is stored in cache memory
c) It is stored in main memory
d) It is stored in secondary memory
Answer: a
10. Which data type can be stored in register?

a) int
b) long
c) float
d) all of the mentioned
Answer: d
11. Which of the following operation is not possible in a register variable?

a) Reading the value into a register variable
b) Copy the value from a memory variable
c) Global declaration of register variable
d) All of the mentioned
Answer: d

12. Which among the following is the correct syntax to declare a static variable register?

a) static register a;
b) register static a;
c) Both static register a; and register static a;
d) We cannot use static and register together
Answer: d
13. Register variables reside in

a) stack
b) registers
c) heap
d) main memory
Answer: b
14. What is the output of this C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         register int x = 0;
  5.         if (x < 2)
  6.         {
  7.             x++;
  8.             main();
  9.         }
  10.     }
a) Segmentation fault
b) main is called twice
c) main is called once
d) main is called thrice
Answer: a
15. What is the output of this C code?

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

  1.     #include 
  2.     register int x;
  3.     void main()
  4.     {
  5.         printf("%d", x);
  6.     }
a) Varies
b) 0
c) Junk value
d) Compile time error
Answer: d

Related

Multiple Choice Questions 8659147983732424252

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