-
Pointers
I have the following questions:
For parts b-e, repeat the declaration and use the results from a.
Code:
int x = 6, y = 5, *px, *py;
a) Write 2 assignment statements that set px and py to point at integers x and y. (I think it is *px = &x, *py = &y
b) Write an output statement using px that print the contents of x. (I have cout << *px << endl
c) Write a statement using py that assigns 20 as the contents of y. (I have *py *=4
d) What is the resulting value of *py + *px? (Would it not be simply 11 using the results from part a)
e) After executing *py = *px, are &x and *py equal? (I say yes. py now equals what px was pointing to which was &x)
I am learning all of this online and just want to make sure that I am doing this right. Thanks
BTW, I tried running this on my compiler but to no avail.
-
a) that is incorrect.
c) if you had properly assigned py to the address of y, then that gives you the number 20, but you are not following the instructions.
e) that is incorrect also. same mistake as in a.
the lines generating the errors should tell you which parts you have made mistakes in.
socratic hint:
what is the result of &x ?