1Given int i someval How would I change the value of someva
1.Given int *i = &some_val;
How would I change the value of some_val to 55 using the pointer i?
i = &55;
i = 55;
*i = 55;
&i = 55;
2.Given
int *i = &some_val;
int **j = &i;
How would I change some_val to 1234 using the pointer j?
**j = 1234;
*j = 1234;
j = 1234;
*j = &1234;
3.Given
int *i = &some_val;
How would I change the memory address that i points to another integer variable another_val?
*i = &another_val;
i = another_val;
i = &another_val;
*i = another_val;
4.Given
int a = 5512;
int *i = &a;
int **j = &i;
int ***k = &j;
What does the following code do?
**k = 0x1234;
Sets a to 0x1234
Sets i to point to 0x1234
Sets k to point to 0x1234
Sets j to point to 0x1234
5.Assuming that 0 is not a valid memory address and given,
int *i = 0;
What would occur if I did:
cout << *i << endl;
Your program would grab the value in memory location 0.
Your program would grab the address in memory location 0.
cout would output 0
Your program would crash for accessing an invalid memory address.
Solution
1.Given int *i = &some_val;
How would I change the value of some_val to 55 using the pointer i?
i = &55;
i = 55;
*i = 55;
&i = 55;
Ans: *i = 55;
2.Given
int *i = &some_val;
int **j = &i;
How would I change some_val to 1234 using the pointer j?
**j = 1234;
*j = 1234;
j = 1234;
*j = &1234;
Ans: **j = 1234;
3.Given
int *i = &some_val;
How would I change the memory address that i points to another integer variable another_val?
*i = &another_val;
i = another_val;
i = &another_val;
*i = another_val;
Ans: i = &another_val;
4.Given
int a = 5512;
int *i = &a;
int **j = &i;
int ***k = &j;
What does the following code do?
**k = 0x1234;
Sets a to 0x1234
Sets i to point to 0x1234
Sets k to point to 0x1234
Sets j to point to 0x1234
Ans: Sets j to point to 0x1234
Since k it triple pointer so, dereferencing twice, it point to j
5.Assuming that 0 is not a valid memory address and given,
int *i = 0;
What would occur if I did:
cout << *i << endl;
Your program would grab the value in memory location 0.
Your program would grab the address in memory location 0.
cout would output 0
Your program would crash for accessing an invalid memory address.
Ans: Your program would crash for accessing an invalid memory address.
Since \'0\' is not a valid address(according to question), then (*i) can not be able to dereference
Please let me know in case of any issue


