Here is a listing of C quiz on “Automatic Variable” along with answers, explanations and/or solutions:
1. What is the scope of an automatic variable?
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
Clarification: None.
2. Automatic variables are allocated space in the form of a __________
a) stack
b) queue
c) priority queue
d) random
Answer: a
Clarification: None.
3. Which of the following is a storage specifier?
a) enum
b) union
c) auto
d) volatile
Answer: c
Clarification: None.
4. If storage class is not specified for a local variable, then the default class will be auto.
a) True
b) False
c) Depends on the standard
d) None of the mentioned
Answer: a
Clarification: None.
5. What will be the output of the following C code?
-
#include
-
void foo(auto int i);
-
int main()
-
{
-
foo(10);
-
}
-
void foo(auto int i)
-
{
-
printf("%dn", i );
-
}
a) 10
b) Compile time error
c) Depends on the standard
d) None of the mentioned
Answer: b
Clarification: None.
6. Automatic variables are stored in ________
a) stack
b) data segment
c) register
d) heap
Answer: a
Clarification: None.
7. What linkage does automatic variables have?
a) Internal linkage
b) External linkage
c) No linkage
d) None of the mentioned
Answer: c
Clarification: None.
8. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
auto i = 10;
-
const auto int *p = &i;
-
printf("%dn", i);
-
}
a) 10
b) Compile time error
c) Depends on the standard
d) Depends on the compiler
Answer: a
Clarification: None.