MCQ
Q.
What will be the output of the following C++ program?
#include
int main() {
int x = 10;
std::cout << "Value: " << x + 5 << std::endl;
return 0;
}
Correct Answer: A
The correct answer is Value: 15.
🔑 Key Points
- The program initializes an integer variable x with the value 10.
- The std::cout statement is used for printing output to the console.
- Inside std::cout, the expression x + 5 is evaluated first. Since x is 10, 10 + 5 results in 15.
- The string literal "Value: " is printed, followed by the computed value 15, and then a newline character (std::endl).
📄 Additional Information
- The #include
directive brings in the input/output stream library, which contains functionalities like std::cout and std::endl. - The main() function is the entry point of every C++ program.
- int x = 10; demonstrates variable declaration and initialization. int specifies the data type as integer.