ExamVeda
Login
Home
Functions and Procedures in C plus plus
?

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
Correct Answer: Option A
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.

Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Nashaib Akbar
Nashaib Akbar 2 years ago
The output of the given code snippet can be determined by evaluating the expression square(3) + square(2).

The square() function takes an integer argument x and returns the square of that integer.

Let's evaluate the expression:

square(3) returns the square of 3, which is 9.
square(2) returns the square of 2, which is 4.
Adding the results of square(3) and square(2) together: 9 + 4 = 13.

So, the output of the code will be: 13 Option No B