C++ Language Test 1

    Question 1C++ Variable Declaration

    What is the correct way to declare an integer variable named count in C++?

    Question 2C++ Arithmetic Operators

    Which of the following is NOT an arithmetic operator in C++?

    Question 3C++ Pointer Declaration

    Which of the following is the correct way to declare a pointer to an integer in C++?

    Question 4C++ If Statement

    Which of the following is the correct syntax of an if statement in C++?

    Question 5C++ For Loop Syntax

    Which of the following is the correct syntax of a for loop in C++?

    Question 6C++ File Stream Declaration

    Which header file is required for file handling in C++?

    Question 7C++ Function Declaration

    Which of the following is the correct way to declare a function in C++ that returns an integer and takes no arguments?

    Question 8C++ Array Declaration

    Which of the following is the correct way to declare an integer array of size 5 in C++?

    Question 9C++ Class Declaration

    Which is the correct way to declare a class in C++?

    Question 10C++ String Declaration

    Which is the correct way to declare a string in C++ using the Standard Library?

    Question 11C++ Guess the Output - Integer Division

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

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

    Question 12C++ Guess the Output – Modulus Operator

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

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

    Question 13C++ Guess the Output – Dereferencing

    What will this code print?

    #include <iostream> using namespace std; int main() { int x = 10; int *ptr = &x; cout << *ptr; return 0; }

    Question 14C++ Guess the Output – Simple If

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

    #include <iostream> using namespace std; int main() { int x = 10; if (x > 5) cout << "Hello"; return 0; }

    Question 15C++ Guess the Output – For Loop

    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++) { cout << i << " "; } return 0; }

    Question 16C++ File Modes

    Which mode is used to append data at the end of a file in C++?

    Question 17C++ Function Definition

    What is the correct way to define a function named add that takes two integers and returns their sum?

    Question 18C++ Guess the Output – Array Initialization

    What will be the output of the following code?

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

    Question 19C++ Guess the Output – Constructor

    What will this program print?

    #include <iostream> using namespace std; class Test { public: Test() { cout << "Constructor called"; } }; int main() { Test obj; return 0; }

    Question 20C++ Guess the Output – String Initialization

    What will the following code print?

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