[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

1 / 14

What is the output of the C++ program?

#include <iostream>
using namespace std;

void fun(int a, int b, int &c,int &d)
{
c += a + b;
d += a - b;
}
 
int main () {
int vl =  5,  v2 =  10, v3 = 2, v4 = 3; 
fun(vl,  v2, v3, v4); 
cout << v3 << "  "<< v4 ;
return 0;
}

A15 -5

B2 3

C17 -2

DNone of the above

Answer: Option (Login/Signup)

Show Explanation

The answer is C.

Explanation:

By associativity of operators, the expressions c += a + b; and d += a - b; will be evaluated from right to left and remember the arguments c and d pass by reference. 

a = 5, b= 10, c= 2, d= 3;


So  c += 15 and c becomes 17, d += -5 and d becomes -2.

Asked In :: Commvault Societe Generale

Post Your Answer Here:     

Reply    
Rate This: +0 -0
    Report


Report Error

Please Login First Click Here