[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

C++ Programming :: Functions - Discussion

Home > C++ Programming > Functions > MCQs Questions Discussion

11 / 14

What is the output of the C++ program?

#include <iostream>
using namespace std;

#define SQ(a)  a*a 
inline int square(int a)
{
return a*a;
}

int main () {
int i, j, k, l;
i = SQ(2 + 3);
j = square(2 + 3);
k = SQ(6 - 1);
l = square(6 - 1);

cout << i << "  "<< j << " "<< k << "  " << l;
return 0;
}

A11 25 -1 25

B11 11 -1 -1

C25 25 25 25

DNone of the above

Answer: Option (Login/Signup)

Show Explanation

So,

SQ(2 + 3) will be replaced with 2 + 3 * 2 + 3 and '*' had more priority in operator precedence. i becomes 2 + 6 + 3 = 11.

square(2 + 3) is a regular function call and j becomes 25.

SQ(6 - 1) will be replaced with 6 - 1 * 6 - 1 and '*' had more priority in operator precedence. k becomes 6 - 6 - 1 = -1.

square(6 - 1) is a regular function call and l becomes 25.

Asked In :: Commvault

Post Your Answer Here:     

Reply    
Rate This: +0 -0
    Report


Report Error

Please Login First Click Here