C++ Language Test 4

    Question 1C++ Size of Data Types

    Which operator in C++ is used to determine the size of a data type or variable?

    Question 2C++ Assignment Operators

    Which of the following is the compound assignment operator in C++?

    Question 3C++ Pointer to Pointer

    What is the correct way to declare a pointer to a pointer of an integer?

    Question 4C++ Switch Statement

    Which of the following is NOT true about the switch statement in C++?

    Question 5C++ Break Statement in Loops

    What does the break statement do in a C++ loop?

    Question 6C++ Guess the Output – Appending File

    What will happen when this program runs?

    #include <iostream> #include <fstream> using namespace std; int main() { ofstream file("log.txt", ios::app); file << "New Entry\n"; file.close(); return 0; }

    Question 7C++ Default Arguments

    Which function declaration is valid with default arguments?

    Question 8C++ Multidimensional Array

    How do you correctly declare a 2D array with 3 rows and 4 columns in C++?

    Question 9C++ Polymorphism – Virtual Function

    Why do we use virtual functions in C++?

    Question 10C++ String Comparison

    Which operator can be used to compare two strings in C++?

    Question 11C++ Guess the Output - Type Casting

    What will be the output of the following C++ code snippet?

    #include <iostream> using namespace std; int main() { int a = 7, b = 2; double result = (double)a / b; cout << result; return 0; }

    Question 12C++ Guess the Output – Bitwise Operator

    What will be the output of the following C++ code snippet?

    #include <iostream> using namespace std; int main() { int x = 6, y = 3; cout << (x & y); return 0; }

    Question 13C++ Guess the Output – Double Pointer

    What will the following program print?

    #include <iostream> using namespace std; int main() { int val = 50; int *p = &val; int **pp = &p; cout << **pp; return 0; }

    Question 14C++ Guess the Output – Switch Case

    What will be the output of the following C++ code snippet?

    #include <iostream> using namespace std; int main() { int day = 3; switch(day) { case 1: cout << "Monday"; break; case 2: cout << "Tuesday"; break; case 3: cout << "Wednesday"; break; default: cout << "Invalid"; } return 0; }

    Question 15C++ Guess the Output – Break

    What will be the output of the following C++ code snippet?

    #include <iostream> using namespace std; int main() { for (int i = 1; i <= 5; i++) { if (i == 3) break; cout << i << " "; } return 0; }

    Question 16C++ Binary File Mode

    Which flag is used to open a file in binary mode?

    Question 17C++ Inline Functions

    What is the purpose of an inline function in C++?

    Question 18C++ Guess the Output – Multidimensional Array

    What will be the output of the following code?

    #include <iostream> using namespace std; int main() { int arr[2][2] = { {1, 2}, {3, 4} }; cout << arr[1][0]; return 0; }

    Question 19C++ Guess the Output – Virtual Function

    What will be the output of this program?

    #include <iostream> using namespace std; class Base { public: virtual void show() { cout << "Base"; } }; class Derived : public Base { public: void show() { cout << "Derived"; } }; int main() { Base *b; Derived d; b = &d; b->show(); return 0; }

    Question 20C++ Guess the Output – String Append

    What will the output of the following code be?

    #include <iostream> #include <string> using namespace std; int main() { string s = "Code"; s.append("Lab"); cout << s; return 0; }