Show the output of the following program You must trace the

Show the output of the following program. You must trace the code to show how you reached the answer. #include int x = 11; int y = 5; void my_first_function(); void my_second_function(); int nain() {int y; y = x; x++; y++; for (int i = 0; i

Solution

#include <bits/stdc++.h>
using namespace std;

int x=11;
int y=5;

void my_first_function();
void my_second_function();

int main(int argc, char const *argv[])
{
   int y;

   y=x; //x is 11,hence y becomes 11
   x++;//x becomes 12
   y++;//y becomes 12

//For loop executes 2 times
   //For loop 1:
   //it calls my_first_function() it will add x(12) and y(5) which is global
   //Hence it prints 17 Addition
   //After that it calls my_second_functionx() it will print x which is 12
   //For loop 2:
   //it calls my_first_function() it will add x(12) and y(5) which is global
   //Hence it prints 17 Addition
   //After that it calls my_second_functionx() it will print x which is 12
   //For loop 1 and //For loop 2 are same nothing is changed because no change in values of x and y


   for (int i = 0; i < 2; ++i)
   {
       my_first_function();
       my_second_function();
   }
   return 0;
}

void my_first_function()
{
   //print addition of x+y i.e.12+5=17
   printf(\"The value of x+y in my_first_function() is %d\ \",x+y );
}

void my_second_function()
{
   //print x value which is 12
   printf(\"The value of x in my_second_function() is %d\ \",x );
}

=======================================================

The value of x+y in my_first_function() is 17
The value of x in my_second_function() is 12
The value of x+y in my_first_function() is 17
The value of x in my_second_function() is 12

=====================================

Tracing is done through comments

 Show the output of the following program. You must trace the code to show how you reached the answer. #include int x = 11; int y = 5; void my_first_function();
 Show the output of the following program. You must trace the code to show how you reached the answer. #include int x = 11; int y = 5; void my_first_function();

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site