C Objective Questions on “Register Variables” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
register int i = 10;
-
int *p = &i;
-
*p = 11;
-
printf("%d %dn", i, *p);
-
}
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?
-
#include
-
int main()
-
{
-
register static int i = 10;
-
i = 11;
-
printf("%dn", i);
-
}
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?
-
#include
-
int main()
-
{
-
register auto int i = 10;
-
i = 11;
-
printf("%dn", i);
-
}
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?
-
#include
-
int main()
-
{
-
register const int i = 10;
-
i = 11;
-
printf("%dn", i);
-
}
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?
-
#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
Answer: d
Clarification: None.