C Programming Questions and Answers – Register Variables – 1

«
»
This section on C interview questions and answers focuses on “Register Variables”. One shall practice these interview 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 Interview questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C interview questions on “Register Variables” along with answers, explanations and/or solutions:

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

advertisement
  1.     #include <stdio.h>
  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
View Answer

Answer: d
Explanation: None.
advertisement
advertisement

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
View Answer

Answer: b
Explanation: None.

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

advertisement
  1.     #include <stdio.h>
  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
View Answer

Answer: b
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  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
View Answer

Answer: b
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  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
View Answer

Answer: b
Explanation: 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
View Answer

Answer: b
Explanation: 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
View Answer

Answer: d
Explanation: None.

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

  1.     #include <stdio.h>
  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
View Answer

Answer: d
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter