II-242 Programming Concepts
18. Why register storage class does not support all data types?
Ans: The CPU registers 8086 in microcomputer are 16-bit registers. The data types float and double
need more than 16 bits space. If we define variables of these data type with register class, no errors
will be shown. The compiler treats them as a variable of auto class.
19. Can we declare a variable in different scopes with different data types? Answer in short.
Yes, we can declare the variable in different scopes with different data types except for some data types
with register scope or storage class.
20. Explain lifetime and visibility of a variable.
Ans:
Lifetime of a variable: Every variable has its lifetime, i.e., its time duration during which its status is
active in the program. We can also say that lifetime of a variable is the time gap between its declaration
and cleanup. The lifetime depends upon the storage class. For example, auto variable gets destroyed
immediately when the function execution is over, whereas static variable remains in the memory.
Visibility of a variable: It is another property. It defines its scope. The scope is of two types, i.e., local
and global. Global is recognized throughout the program, whereas the local variable scope is limited to
the declaration block.
Multiple-choice Questions
1. A static variable is one that .
(a) Retains its value throughout the life of the program
(b) Cannot be initialized
(c) Is initialized once at the commencement of the execution and cannot be changed at the run time
(d) Is the same as an automatic variable, but is placed at the head of the program
2. An external variable is one .
(a) That is globally accessible by all functions
(b) That is declared outside the body of any function
(c) That resides in the memory till the end of the program
(d) All of the above
3. If a storage class is not mentioned in the declaration, then default storage class is .
(a) auto (b) static (c) extern (d) register
4. If the CPU fails to keep the variables in CPU registers, in that case the variables are assumed
.
(a) auto (b) static (c) extern (d) None of the above
5. What will be the value of variable x on execution of the following program?
int x;
void main()
{
clrscr();
x++;
printf("
%d",x);
}
M11_ITL-ESL4791_02_SE_C11.indd 242 12/22/2012 5:05:15 PM