C Programming Questions and Answers on Register Variables for Freshers

https://www.computersprofessor.com/2017/12/c-programming-questions-and-answers-on_7.html
1. What is the output of this C code?
#include
int main()
{
register int i = 10;
int *p = &i;
*p = 11;
printf("%d %d\n", i, *p);
}
a) Depends on whether i is actually stored in machine register
b) 10 10
c) 11 11
d) Compile time error
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?
#include
int main()
{
register static int i = 10;
i = 11;
printf("%d\n", i);
}
a) 10
b) Compile time error
c) Undefined behaviour
d) 11
b) Compile time error
c) Undefined behaviour
d) 11
Answer: b
4. What is the output of this C code?
#include
int main()
{
register auto int i = 10;
i = 11;
printf("%d\n", i);
}
a) 10
b) Compile time error
c) Undefined behaviour
d) 11
b) Compile time error
c) Undefined behaviour
d) 11
Answer: b
5. What is the output of this C code?
#include
int main()
{
register const int i = 10;
i = 11;
printf("%d\n", i);
}
a) 10
b) Compile time error
c) Undefined behaviour
d) 11
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?
#include
void main()
{
register int x = 5;
m();
printf("x is %d", x);
}
void m()
{
x++;
}
a) 6
b) 5
c) Junk value
d) Compile time error
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?
#include
void main()
{
register int x = 0;
if (x < 2)
{
x++;
main();
}
}
a) Segmentation fault
b) main is called twice
c) main is called once
d) main is called thrice
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?
#include
void main()
{
register int x;
printf("%d", x);
}
a) 0
b) Junk value
c) Compile time error
d) Noting
b) Junk value
c) Compile time error
d) Noting
Answer: b
16. What is the output of this C code?
#include
register int x;
void main()
{
printf("%d", x);
}
a) Varies
b) 0
c) Junk value
d) Compile time error
b) 0
c) Junk value
d) Compile time error
Answer: d