(Q) Pointer printsΒΆ

Goal: I will learn how use pointers in C++.

Instructions: Consider the example codes below and check the true claims.

Consider the code below:

1
2
3
4
int x = 3;
int* ptr = &x;
cout << ptr << endl;
cout << *ptr << endl;

Check the true claims based on the code above.

Consider the code below:

1
2
3
4
5
int x;
int* ptr = &x;
x = 4;
cout << ptr << endl;
cout << *ptr << endl;

Check the true claims based on the code above.

Consider the code below:

1
2
3
4
5
int x;
int* ptr = &x;
*ptr = 4;
cout << ptr << endl;
cout << *ptr << endl;

Check the true claims based on the code above.

Consider the code below:

1
2
3
4
int x;
int* ptr = 4;
cout << ptr << endl;
cout << *ptr << endl;

Check the true claims based on the code above.

Consider the code below:

1
2
3
4
5
6
7
int x;
int* ptr = &x;
x = 5;
cout << ptr << endl;
cout << *ptr << endl;
cout << x << endl;
cout << &x << endl;

Check the true claims based on the code above.