Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Explain methods of metal extraction with examples.

Answered: 1 week ago