In C int funcint op1 int op2 bool flag if flag return op1

In C++

int func(int op1, int op2, bool flag)

{

       if (flag)

             return op1 / op2;

       else

              return op1 – op2;

}

Given the function definition above, what will the following line print out?

cout << func(6, 3, false) << endl;

Answer

a) -3

b) 3

c) 2

d) 0

e) 0.5

Solution

Answr

It will print out 3 because as in the function caling we are passing the value of bool as false so when it enters the if condition the condition does not satisfy so it will then pass to else condition. in else condition we have return op1-op2 where op1=6 and op2=3 so op1-op2=3 so it will print 3.

In C++ int func(int op1, int op2, bool flag) { if (flag) return op1 / op2; else return op1 – op2; } Given the function definition above, what will the following

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site