MCQs on C Storage classes
1. Longevity of a variable refers toa) The duration for which the variable retains a given value during the execution of a program.
b) The portion of a program in which the variable may be visible.
c) Internal linkage of a variable.
d) External linkage of a variable.
View Answer / Hide AnswerANSWER: a) The duration for which the variable retains a given value during the execution of a program.
2. Which is not a storage class?a) Auto
b) Struct
c) Typedef
d) Static
View Answer / Hide Answer3. extern int s;
int t;
static int u;
main()
{
}
Which of s, t and u are available to a function present in another file?a) Only s
b) S & u
c) S, t, u
d) None
View Answer / Hide Answer4. Which of the following statement are correct?(i) The value stored in the CPU register can always be accessed faster than that stored in memory.
(ii) A register storage class variable will always be stored in a CPU register.
a) Only I is correct
b) Only II is correct
c) Both I & II are correct
d) Both I & II are incorrect
View Answer / Hide AnswerANSWER: a) Only I is correct
5. What is the output of the following program?#include< stdio.h>
int main()
{
static int a = 3;
printf(“%d”, a --);
return 0;
}
a) 0
b) 1
c) 2
d) 3
View Answer / Hide Answer6. Which of the following statement are correct?(iii) The maximum value a variable can hold depends upon its storage class.
(iv) By default all variables enjoy a static storage class.
a) Only I is correct
b) Only II is correct
c) Both I & II are correct
d) Both I & II are incorrect
View Answer / Hide AnswerANSWER: d) Both I & II are incorrect
7. What will be the output of the following program?#include< stdio.h>
void fun()
{
fun();
Return 0;
}
void fun()
{
auto int I = 1;
register char a = ‘D’;
static int p = 0;
printf(“%d %d %ld”, I, a, p);
}
a) 1 D 0
b) 1 0 0
c) 0 D 1
d) 1 68 0
View Answer / Hide Answer8. What will be the output of the following program?#include < stdio.h>
static int y = 1;
int main()
{
static int z;
printf(“%d %d”, y, z);
return 0;
}
a) Garbage value
b) 0 0
c) 1 0
d) 1 1
View Answer / Hide Answer9. What will be the storage class of variable I in the code written below?#include< stdio.h>
int main()
{
int I = 10;
printf(“%d”, i);
return 0;
}
a) Automatic storage class
b) Extern storage class
c) Static storage class
d) Register storage class
View Answer / Hide AnswerANSWER: a) Automatic storage class
10. What will be the output of the following code?static int I = 5;
main()
{
int sum = 0
do
{
sum + = (1/i);
}while(0 < I - -);
printf(“sum of the series is %d”, sum);
}
a) It will print the sum of the series 1/5+1/4+…+1/1.
b) It will produce a compilation error.
c) It will produce a run time error.
d) None.
View Answer / Hide AnswerANSWER: c) It will produce a run time error.
11. In case of a conflict between the names of a local and global variable what happens?a) The global variable is given a priority.
b) The local variable is given a priority.
c) Which one will get a priority depends upon which one is defined first.
d) The compiler reports an error.
View Answer / Hide AnswerANSWER: b) The local variable is given a priority.
12. What will be the output of the following program?#include< stdio.h>
int main()
{
static unsigned int a = 23;
register unsigned char c = ‘R’;
auto long unsigned q = 345L;
static long signed p = 345L;
printf(“a = %u c = %c”, a ,c);
printf(“\nq = %ld p = %ld”, q, p);
return 0;
}
a) a=23 c=R q = 345 p = 345
b) A=23 c=R 0 0
c) Garbage value
d) A=23 c=R q = 345 p = 345
View Answer / Hide AnswerANSWER: a) a=23 c=R q = 345 p = 345
13. What will be the output of the following program?#include< stdio.h>
int main()
{
register int I = 2;
static char ch = ‘A’;
auto float j;
int k;
k = ++ch && I;
k = ++ch;
j = i-- + ++k * 2;
printf(“%d %f”, k , j);
return 0;
}
a) B 3
b) 65 138.000000
c) 68 138.000000
d) A 138
View Answer / Hide Answer14. What will be the output of the following program?#include< stdio.h>
Void f(static int*, extern int);
Static int b = 12;
Int main()
{
Static int a[5];
Register int I;
For(I = 0; I < 2; I ++);
A[i++] = 2 * i++;
F(a, b);
For(I = 0; I < 2; I ++)
Printf(“%d”, b++);
Return 0;
}
Void f (static int *x, extern int y)
{
Register int I;
For(I = 0; I < 2; I ++)
*(++x +1) + = 2;
Y + = 2;
}
a) 0 0
b) 0 6
c) 0 12
d) 12 12
View Answer / Hide Answer15. Where will the space be allocated for an automatic storage class variable?a) In CPU register
b) In memory as well as in CPU register
c) In memory
d) On disk.
View Answer / Hide Answer16. What will be the output of the following code?#include< stdio.h>
int main()
{
extern int a;
static char j = ‘E’;
printf(“%c %d”, ++j, ++a);
return 0;
}
a) E 2
b) F 1
c) F Garbage
d) F 0
View Answer / Hide Answer17. For which of the following situation should the register storage class be used?a) For local variable in a function
b) For loop counter
c) For collecting values returned from a function
d) For variables used in a recursive function
View Answer / Hide AnswerANSWER: b) For loop counter
18. Which of the following statement is correct?(i) A function can also be declared as static.
(ii) The default value of an external storage class variable is zero.
a) Only I is correct
b) Only II is correct
c) Both I & II are correct
d) Both I & II are incorrect
View Answer / Hide AnswerANSWER: c) Both I & II are correct
19. Which of the following statement is correct about the code snippet given below?#include < stdio.h>
extern int p;
int sum = 5;
int main()
{
p = bomb();
printf(“%d %d”, sum, p);
return 0;
}
bomb()
{
sum ++;
return (sum);
}
a) The code reports an error as expression syntax
b) The code gets compiled successfully but will not give any output.
c) The code gives an output as 6.
d) The code reports an error as bomb undefined.
View Answer / Hide AnswerANSWER: d) The code reports an error as bomb undefined.
20. Which of the following statement is correct about the code snippet give below?#include< stdio.h>
int main()
{
gotorc(10, 20);
printf(“Hello World”);
return 0;
}
#include “goto.c”
a) The code gives an output as Hello World
b) Code reports an error as undefined symbol gotorc
c) The code gets compile successfully but will not give any output
d) The code gives an output as 10 20
View Answer / Hide AnswerANSWER: b) Code reports an error as undefined symbol gotorc