250+ TOP MCQs on Register Variables and Answers

C Objective Questions on “Register Variables” along with answers, explanations and/or solutions:

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

  1.     #include 
  2.     int main()
  3.     {
  4.         register int i = 10;
  5.         int *p = &i;
  6.         *p = 11;
  7.         printf("%d %dn", 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
Clarification: None.

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
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         register static int i = 10;
  5.         i = 11;
  6.         printf("%dn", i);
  7.     }

a) 10
b) Compile time error
c) Undefined behaviour
d) 11

Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         register auto int i = 10;
  5.         i = 11;
  6.         printf("%dn", i);
  7.     }

a) 10
b) Compile time error
c) Undefined behaviour
d) 11

Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         register const int i = 10;
  5.         i = 11;
  6.         printf("%dn", i);
  7.     }

a) 10
b) Compile time error
c) Undefined behaviour
d) 11

Answer: b
Clarification: None.

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
Clarification: None.

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
Clarification: None.

8. What will be the output of the following 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
Clarification: None.

Leave a Reply

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