CSE 250 Lecture 3: 2.14.17 recitation 3 Pointers and References
Document Summary
Pointers std::cout << *int _ptr += 10; std::cout << num << std::endl; std::cout << othernum << endl; std::cout << *int_ptr << endl; If we were printing int_ptr it would print the address of x, but printing *int_ptr means that we go to int_ptr, get the address stored there, then print what is stored at that address (in this case, 7). Printing x and *int_ptr would give you the same thing. This would print 17 and it would change x(cid:859)s (cid:448)alue to 17. **cha(cid:374)gi(cid:374)g so(cid:373)ethi(cid:374)g(cid:859)s poi(cid:374)ter (cid:449)ill result i(cid:374) the a(cid:272)tual thi(cid:374)g (cid:271)ei(cid:374)g (cid:272)ha(cid:374)ged. This erases our link form int_ptr to x, and creates a new link from int_ptr to othernum. This would print 17, 200, 200 because we are changing the value of othernum when we change *int_ptr si(cid:374)(cid:272)e that is the address it(cid:859)s poi(cid:374)ti(cid:374)g to. Usi(cid:374)g the star operator (cid:449)e (cid:272)a(cid:374) sa(cid:455) li(cid:374)k to this (cid:448)aria(cid:271)le(cid:859)s address.