CPP Variables MCQ
Cpp MCQ(1) Global variables are created in:
A) ROM
B) Cache
C) Hard disk
D) RAM
Explanation
All type of variables including global variables are created in main memory called RAM. These variables are different in their lifetime and access.
(2) Which of the following variable type can be accessible anyway in the program
A) Static
B) Global
C) Local
D) Register
Explanation
Global variables are created outside of the main() function and can be accessible in entire program.
(3) Which of the following type of variables hold their data throughout the program executioner
A) Local
B) Static
C) Global
D) Both b and c
Explanation
Static and global variables hold their data throughout the lifetime of program execution. The difference between global and static variables is that global variables are accessible throughout the entire program while static variables can only be accessible inside function where these are created.
(4) Which of the following default storage class specifier for declaring local variables?
A) Register
B) Static
C) Local
D) Auto
Explanation
Auto storage class specifier is the default for declaring local variables. We can write it before declaration of local variables. If auto kwyword is not used then variables are by default declared as local.
(5) How many types of variables can be created in C/C++ programs
A) 1
B) 2
C) 3
D) 4
Explanation
There are four types of variables that can be created in C/C++. These are Global, Local, Static and Register. Most commonly local variables are created in programs.
(6) Which of the following type of local variable retain its value throughout program execution
A) Auto
B) Register
C) Static
D) None
Explanation
Static variables are local variable that are declared inside function body. These variables are created at first function call and retain their value throught the lifetime of program.
(7) Variable has the following properties
A) Name
B) Address
C) Type
D) All of These
Explanation
Name, Address, Type and Value are four properties of variable.