Look at the below code and answer the following questions in

Look at the below code and answer the following questions: int increment (int a) {return a + 1;//line 1 a = 33;//line 2} int main() {int result = increment(increment(increment(1)));} What is the return type of the function? Is it possible to use return as shown in main? If so what would the result be? Does \"line 2\" get compiled? Does it get executed?

Solution

a. Return type of the function increment is int.

b. yes, it is possible. The ouput is 4.

#include <iostream>
using namespace std;

int increment(int a)
{
   return a+1;
   a=33;
}
int main()
{
   int result = increment(increment(increment(1)));
   cout<<result;
   return 0;
}

output:

Success time: 0 memory: 3468 signal:0

c. Yes the line a=33; will be compiled . No, line 2 will not get executed because the function will return out

increment(increment(increment(1);

increment(increment(2);

increment(3);

=4

 Look at the below code and answer the following questions: int increment (int a) {return a + 1;//line 1 a = 33;//line 2} int main() {int result = increment(inc

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site