cs246-s11-001-may26

cs246-s11-001-may26 - CS 246 (Spring 2011) Section 1...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 246 (Spring 2011) – Section 1 Thursday 26 May Pointers/References, Arrays, Structures
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 246 (Spring 2011) - Section 001 - Thursday 26 May 2 Today's Agenda Some notes about last class Finish 2.7.2 (pointers/references) 2.7.3 Aggregates Arrays Structures
Background image of page 2
CS 246 (Spring 2011) - Section 001 - Thursday 26 May 3 Continued from last day Partial memory diagram int x = 5; int *p1; Rewrite rules for p1 = &x; Can a pointer variable point to itself?
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 246 (Spring 2011) - Section 001 - Thursday 26 May 4 Reference pointers Some motivation Say p1 and p2 are of type int * *p1 = (*p1-*p2)/(*p2 * *p1)+(10/*p1); (tedious and error-prone) p1 = (p1 – p2) / (p2 * p1) + (10 / p1); (would be much nicer) Reference pointers provide implicit dereference int z = 3, u = 4; int &r1 = z; int &r2 = u; cout << r1 + r2 << endl;
Background image of page 4
CS 246 (Spring 2011) - Section 001 - Thursday 26 May 5 Reference pointers (ctd.) The name of a reference pointer means the value of its target r1 = r2; // rewrite rules? cout << r1 << endl; u = 20; cout << r1 << endl; The address of a reference pointer means the address of its target cout << z << “ “ << r1 << endl; cout << &z << “ “ << &r1 << endl;
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 246 (Spring 2011) - Section 001 - Thursday 26 May 6 Reference pointers (ctd.) Reference pointers are treated like a const (literal) Its contents cannot change at run-time
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/08/2011 for the course CS 246 taught by Professor Wormer during the Spring '08 term at Waterloo.

Page1 / 21

cs246-s11-001-may26 - CS 246 (Spring 2011) Section 1...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online