Question: Hi, I have a question about the C++ pointer int main() { int num1 = 5, num2 = 6; int *p1 = &num1; int *p2
Hi, I have a question about the C++ pointer
int main() {
int num1 = 5, num2 = 6;
int *p1 = &num1;
int *p2 = &num2;
*p1 = 90;
std::cout << num1 << std::endl; // num1 unchanged, still 5
}
p1 is pointing to num1, and *p1 gets me the value stored on the address that p1 points (which is &num1), but why num1 is unchanged after *p1 = 90?
And how can I modify the value of num1 with the pointer p1?
Thank you, will upvote for detailed answer!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
