C Programming Questions and Answers – Register Variables
C Programming Questions and Answers – Register Variables
1.What is the output of this C code?
#include <stdio.h>
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
View Answer
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
3.What is the output of this C code?
#include <stdio.h>
int main()
{
register static int i = 10;
i = 11;
printf(“%d\n”, i);
}
a) 10
b) Compile time error
c) Undefined behaviour
d) 11
View Answer
4.What is the output of this C code?
#include <stdio.h>
int main()
{
register auto int i = 10;
i = 11;
printf(“%d\n”, i);
}
a) 10
b) Compile time error
c) Undefined behaviour
d) 11
View Answer
5.What is the output of this C code?
#include <stdio.h>
int main()
{
register const int i = 10;
i = 11;
printf(“%d\n”, i);
}
a) 10
b) Compile time error
c) Undefined behaviour
d) 11
View Answer
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
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
8.What is the output of this C code?
#include <stdio.h>
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
View Answer
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
View Answer
10.Which data type can be stored in register?
a) int
b) long
c) float
d) All of the mentioned
View Answer
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
View Answer
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 (a) and (b)
d) We cannot use static and register together.
View Answer
13.Register variables reside in
a) stack
b) registers
c) heap
d) main memory
View Answer
14.What is the output of this C code?
#include <stdio.h>
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
View Answer
15.What is the output of this C code?
#include <stdio.h>
void main()
{
register int x;
printf(“%d”, x);
}
a) 0
b) Junk value
c) Compile time error
d) Noting
View Answer
16.What is the output of this C code?
#include <stdio.h>
register int x;
void main()
{
printf(“%d”, x);
}
a) varies
b) 0
c) Junk value
d) Compile time error