Question

what is the output for the following code? explain the steps. /*#include <iostream> using namespace std;...

what is the output for the following code? explain the steps.

/*#include <iostream>

using namespace std;

int f(int &i)

{

i = 10;

return(5 * i);

}

int main()

{

int n = 5;

f(n);

cout << n << "\n";

return 0;

}

#include <iostream>

using namespace std;

int sub1(int n)

{

n--;

return n;

}

int main()

{

int m = 10;

for(int j = 0; j < 10; j++)

m -= sub1(j);

cout << m << "\n";

return 0;

}

#include <iostream>

using namespace std;

int myfunc(double);

int myfunc(float);

int main()

{

cout << myfunc(3.6) << "\n";

return 0;

}

int myfunc(double n)

{

return n * 2.0;

}

#include <iostream>

using namespace std;

int main()

{

int i = 1;

double x = 1.111;

cout << i << " " << x << "\n";

{

int x = 2;

double i = 2.222;

cout << i << " " << x << "\n";

}

return 0;

}

#include <iostream>

using namespace std;

int sum(int pt[], int n)

{

int temp = 0;

for (int i = 0; i < n; ++i)

{

temp += pt[i];

}

return temp;

}

int main()

{int i;

int total;

int pt[5];

for ( i = 0; i < 5; i++)

pt[i] = i;

total = sum(pt, 3);

cout << total << " " << i << endl;

return 0;

}

#include <iostream>

using namespace std;

int func ( string plant5, char plant4[])

{

for (char &x: plant5)

cin >> x;

}

int main()

{

char plant1[] = "Tree";

char plant2[] = {'T','R','E','E'};

cout << "i " << plant2[50] << endl;

char plant3[80] = "Tree";

char plant4[] = {'T','R','E','E','\0'};

string plant5 = "Tree";

cout << "i " << plant5[2];

func(plant5,plant4);

for (char x: plant5)

cout << x;

return 0;

}

*/

#include <iostream>

using namespace std;

double triangle(double base , double height = 10.0 ); //right

//double triangle(double base = 10.0, double height ); //wrong

int main()

{

cout << triangle(10.0) << "\n";

return 0;

}

double triangle(double base, double height)

{

return 0.5*base*height;

}

/*

#include <iostream>

using namespace std;

void what( int &a) // add const before int to fix the syntax error

{

cout << a;

}

int main()

{

const int whatVar = 1;

int b = 100;

what(whatVar);

cout << whatVar << " " << b;

}

I will a syntax error because if I pass a const

variable to a function I must add the const on the

function header.

*/

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Question 1:

Output :

Explanation :

  • Here a method f is defined and parameter to this method is passed by reference.
  • In the main on line 10 variable n=5 of integer type is declared.
  • on line 11 method f is called and n is passed to method.
  • But here parameter is passed as reference hence i will become 10 and 5*10=50 and return 50.
  • but this return value is not stored in variable and on line 12 n is printed hence will get 10 as output.

*********************************

Question 2:

Output :

Explanation :

  • Here method sub1() with n as parameter will decrement value of n by -1. and return n.
  • In main method m=1 and for loop value of j will go from 0 to 9.
  • When sub1(0) is called value of m becomes 11 because sub1(0) will return -1 and m=10-(-1) will be 11.
  • like wise will get the value of j from 1 to 9 and finally will get -25.

*********************************

Question 3:

Output :

Explanation :

  • Here myfun() is declared and from the main to this function 3.6 parameter is passed.
  • and will get the result as 7.

*********************************

Question 4:

Output :

*********************************

Question 5:

Output :

*********************************

Question :

Output :

**************************

Question :

Output :

******************************

Question :

Output :

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
what is the output for the following code? explain the steps. /*#include <iostream> using namespace std;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT