11
What is the output of the following code: int square(int x) { return x * x; } int main() { cout << square(3) + square(2); } in C++?
Answer & Solution
Answer: Option
A
Solution:
The given code defines a function named
square which takes an integer x as input and returns the square of x. In the main function, square(3) returns 9 and square(2) returns 4. When these values are added together and printed, the output will be 9 + 4 = 13.