Quiz on Constants and Variable Scope in C++
Generally, the scope of a variable is the extent within which it is accessible, declared or used. You should move to the quiz arena once you have gained confidence and mastered the concept of variable scope. We will test your concepts on constants and variable scope in C++ in this quiz. Let us start the quiz now.
0 of 15 Questions completed Questions: You have already completed the quiz before. Hence you can not start it again. Quiz is loading… You must sign in or sign up to start the quiz. You must first complete the following: 0 of 15 Questions answered correctly Your time: Time has elapsed You have reached 0 of 0 point(s), (0) Earned Point(s): 0 of 0, (0) What is the output of the following code snippet? #include <iostream> using namespace std; int main() { int x = 1, y = 2, z = 3; cout<<” x =”<<x<<” y = ” <<y<<” z = “<< z<<endl; { int x = 10; float y = 20; cout<<” x =”<<x<<” y = ” <<y<<” z = “<< z<<endl; { int z = 100; cout<<” x =”<<x<<” y = ” <<y<<” z = “<< z<<endl; } } return 0; } #include <iostream> using namespace std; int x = 1, y = 2, z = 3; int main() { cout<<” x =”<<x<<” y = ” <<y<<” z = “<< z<<endl; { int x = 10; float y = 20; cout<<” x =”<<::x<<” y = ” <<::y<<” z = “<< z<<endl; { int z = 100; cout<<” x =”<<x<<” y = ” <<y<<” z = “<< z<<endl; } } return 0; } #include <iostream> using namespace std; int a=10; int main() { int a = 20; cout<<a<<” “; a=25; cout<<::a; return 0; } #include <iostream> using namespace std; static int var; int variable() { var++; return var; } int main() { var=20; cout<<variable(); cout<<variable(); } #include <iostream> using namespace std; static int var; int variable() { var++; return var; } int main() { var=20; cout<<variable(); cout<<variable(); } #include <iostream> using namespace std; extern int var=0; int variable() { var++; return var; } int main() { var=21; cout<<variable(); cout<<variable(); } #include <iostream> using namespace std; int variable(int var) { var++; return var; } int main() { { int var = 10; } { cout<<variable(var); cout<<variable(var); } return 0; } #include <iostream> using namespace std; int variable(int var) { var++; return var; } int main() { { int var = 032; cout<<variable(var); cout<<variable(var); } return 0; } #include <iostream> using namespace std; int variable; int main() { { int var; } int v; return 0; } #include <iostream> using namespace std; int i=5; int main() { int i=20; for ( i=0; i<5; i++ ) { int i = 10; cout<<i<<” “; i++; } cout<<i; return 0; } #include <iostream> using namespace std; int tmp=20; void func() { static int tmp=10; cout<<tmp<<” “; tmp++; } int main() { cout<<tmp<<” “; func(); cout<<tmp<<” “; func(); return 0; } #include <iostream> using namespace std; int const tmp=20; void func() { static const int tmp=10; cout<<tmp<<” “; } int main() { cout<<tmp<<” “; func(); cout<<tmp<<” “; func(); return 0; } #include <iostream> using namespace std; int const tmp=20; void func() { static const int tmp=10; cout<<tmp<<” “; } int main() { cout<<tmp<<” “; func(); tmp++; cout<<tmp<<” “; func(); return 0; } Quiz Summary
Information
Results
Results
0 Essay(s) Pending (Possible Point(s): 0) Categories
1. Question
2. Question
3. Question
4. Question
5. Question
6. Question
7. Question
8. Question
9. Question
10. Question
11. Question
12. Question
13. Question
14. Question
15. Question
Summary
Our C++ quiz on constants and Variable Scope comes to an end. In order to excel further in learning C++, you need to master this topic. Hence, you should clear any doubts you have first before proceeding to the next step. Let us know what you think by dropping a comment. Learn well!