TCS Variables and Registers Questions

1. What is the output of this C code?
#include
void main()
{
static int i;
printf(“i is %d”, i);
}
a) 0
b) 1
c) Garbage Value
d) Run time error
Answer:a

2. What is the output of this C code?
#include
int *i;
int main()
{
if (i == NULL)
printf(“true\n”);
return 0;
}
a) true
b) true only if NULL value is 0
c) Compile time error
d) Nothing
Answer:a

3. What is the output of this C code?
#include
static int i;
void main()
{
int i;
printf(“i is %d”, i);
}
a) 0
b) Garbage Value
c) Run time error
d) Nothing
Answer:b

4. What is the output of this C code?
#include
static int x = 5;
void main()
{
x = 9;
{
int x = 4;
}
printf(“%d”, x);
}
a) 9
b) 4
c) 5
d) 0
Answer:a

5. The scope of an automatic variable is:
a) Within the block it appears
b) Within the blocks of the block it appears
c) Until the end of program
d) Within the block it appears & Within the blocks of the block it appears
Answer:d

6. Automatic variables are allocated space in the form of a:
a) stack
b) queue
c) priority queue
d) random
Answer:a

7. Which of the following is a storage specifier?
a) enum
b) union
c) auto
d) volatile
Answer:c

8. Automatic variables are stored in
a) stack
b) data segment
c) register
d) heap
Answer:a

9. What is the output of this C code?
#include
int main()
{
register int i = 10;
int *q = &i;
*q = 11;
printf(“%d %d\n”, i, *q);
}
a) Depends on whether i is actually stored in machine register
b) 10 10
c) 11 11
d) Compile time error
Answer:d

10. 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

11. Register variables reside in
a) stack
b) registers
c) heap
d) main memory
Answer:b

12. 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