Detailed Print – Computer Sir Ki Class  Solved Problem#CPP#7684

## Problem Statement - Output writing using structure copy and strcat use

```struct Play {char Arr;int n;};
int main()
{
struct Play P={"JUDO",2};
P.Arr='L';
P.n+=2;
cout<<P.Arr<<"#"<<P.n<<endl;
Play R = P;
R.Arr='S';R.Arr='O';
strcat(R.Arr,"KU");
R.n-=3;
cout<<R.Arr<<"#"<<R.n<<endl;
return 0;
}```

Write the output of the above program. Assume that required header files are present.

## Solution

```		#include <iostream>
#include <cstring>
using namespace std;
struct Play {char Arr;int n;};
int main()
{
struct Play P={"JUDO",2};
P.Arr='L';
P.n+=2;
cout<<P.Arr<<"#"<<P.n<<endl;
Play R = P;
R.Arr='S';R.Arr='O';
strcat(R.Arr,"KU");
R.n-=3;
cout<<R.Arr<<"#"<<R.n<<endl;
return 0;
} ```

## Run Output

``````LUDO#40
SODOKU#1
``````

## Solved Problem Understanding

struct Play P={“JUDO”,2}; //structure initialised with Arr[] content as JUDO and n as 2
P.Arr=’L’; //JUDO becomes LUDO as 0th character changed
P.n+=2;         //n becomes 4 as 2 is added to previous value
cout<<P.Arr<<“#”<<P.n<<endl;  //LUDO#4 printed
Play R = P;  //Another copy of structure object made as R which will have final values as contained in P
R.Arr=’S’;R.Arr=’O’; //R’s arr[] now becomes SUDO
strcat(R.Arr,”KU”); //Additional KU is concatenated to SUDO making it SODUKU
R.n-=3; //R’s n us reduced by 3 making it 1
cout<<R.Arr<<“#”<<R.n<<endl; //SODOKU#1 is printed