Complete the code to declare a variable inside the main function.
int main() {
int [1] = 10;
return 0;
}The variable name inside main should be a valid identifier like number.
Complete the code to print the value of the local variable inside the function.
#include <iostream> using namespace std; void show() { int x = 5; cout << [1] << endl; } int main() { show(); return 0; }
The variable x is declared inside show() and can be printed there.
Fix the error by completing the code to access the global variable inside the function.
#include <iostream> using namespace std; int [1] = 100; void printGlobal() { cout << [1] << endl; } int main() { printGlobal(); return 0; }
The global variable name must be the same in declaration and usage. Here, globalVar is used.
Fill both blanks to declare a variable inside a block and print it.
#include <iostream> using namespace std; int main() { { int [1] = 20; cout << [2] << endl; } return 0; }
The variable declared inside the block is blockVar, which is also printed inside the same block.
Fill all three blanks to declare a global variable, shadow it inside main, and print both values.
#include <iostream> using namespace std; int [1] = 50; int main() { int [2] = 100; cout << ::[3] << endl; // global cout << [2] << endl; // local return 0; }
:: to access the global variable inside main.The global variable count is declared outside main. Inside main, a local variable count shadows the global one. Using ::count accesses the global variable.