Quick Print – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
siteicon
Solved Problem Solved Problem#CPP#5834

Problem Statement - Output Writing – passing integers as ref and as def value

Write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program .

void Position (int &C1, int C2=3)
{
  C1+=2;
  C2+=2;   //Original paper had this incorrectly written as Y
}
void main()
{
  int P1=20, P2=4;
  Position(P1);
  cout<<P1<<","<<P2<<endl;
  Position(P2,P1);
  cout<<P1<<","<<P2<<endl;
}

Solution

		 

Run Output

22,4
22,6

22,4
22,6