Storage-Classes

Question 1
The default storage class for functions in ‘C’ language is:
A
Static
B
Register
C
Extern
D
Auto
Question 1 Explanation: 
The default storage class for variable is auto and function is extern.
We can use functions in multiple files with the help of header files.
Question 2
Which of the following storage classes have global visibility in C/C++ ?
A
Auto
B
Extern
C
Static
D
Register
Question 2 Explanation: 
→ Register and auto variables have limited scope (the block in which they are declared) and limited lifetimes (as for automatic variables). However, in some applications it may be useful to have data which is accessible from within any block and/or which remains in existence for the entire execution of the program. Such variables are called global variables. The scope of external variables is global.
Question 3
After 3 calls of the c function bug( ) below, the values of i and j will be :
int j=1;
bug( )
{
static int i=0; int j=0;
i++;
j++;
return (i);
}
A
i = 0, j = 0
B
i = 3, j = 3
C
i = 3, j = 0
D
i = 3, j = 1
Question 3 Explanation: 
Step-1: Initially i=0 but given as static. The scope is lifetime.
Step-2: Call-1: i=1 and j=1
Call-2: i=2 and j=1 because ‘i’ is static ‘j’ is again become 0 when it starts new call.
Call-3: i=3 and j=1 because ‘i’ is static ‘j’ is again become 0 when it starts new call.
Note: A static ‘int’ variable remains in memory while the program is running.
There are 3 questions to complete.

Access quiz wise question and answers by becoming as a solutions adda PRO SUBSCRIBER with Ad-Free content

Register Now

If you have registered and made your payment please contact solutionsadda.in@gmail.com to get access