Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started