In: Computer Science
What would version control be for this piece of code in C++?
#include <iostream>
using namespace std;
int main()
{
int x = 5;
int *p = &x;
*p = 6;
int **q = &p;
int ***r = &q;
cout <<*p<<endl;
cout <<*q<<endl;
cout <<**q<<endl;
cout <<*(*r)<<endl;
cout <<*(*(*r))<<endl;
***r = 10;
cout <<x<<endl;
**q = *p + 2;
cout <<x<<endl;
return 0;
}
ANSWER : HERE IS THE ANSWER FOR YOUR QUESTION:
----------------------------------------------------------------------------------------------------------------
CODE:
#include <iostream>
using namespace std;
int main()
{
int x = 5;
int *p = &x;
*p = 6;
int **q = &p;
int ***r = &q;
cout <<*p<<endl;
cout <<*q<<endl;
cout <<**q<<endl;
cout <<*(*r)<<endl;
cout <<*(*(*r))<<endl;
***r = 10;
cout <<x<<endl;
**q = *p + 2;
cout <<x<<endl;
return 0;
}
----------------------------------------------------------------------------------------------------------------
SNIPPET:

----------------------------------------------------------------------------------------------------------------
OUTPUT:

Explanation:
here , the concept of pointer is used extensively .
here , p is a pointer to the variable x and store its address
and , we increase the complexity of the program using pointer to pointer concept
and we get the values as shown in the output
----------------------------------------------------------------------------------------------------------------
I hope this would help you out.
If you like my answer , please upvote
If you have any doubt, you can provide comment /feedback below the answer
Thanks