LEC20081010 - Introduction to Computer Programming CSC180...

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

View Full Document Right Arrow Icon
Introduction to Computer Programming October 10, 2008 CSC180 Fall 2008, University of Toronto
Background image of page 1

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

View Full Document Right Arrow Icon
Pointers as function arguments Exchange the values of two variables: void swap(int *x, int *y) { int temp; temp = *x; *x = *y; *y = temp; } int main() { int x = 1, y = 2; swap(&x, &y); CSC180 Fall 2008, University of Toronto 1
Background image of page 2
printf(‘‘x: %d, y: %d\n’’, x, y); /* print x: 2, y: 1 */ return 0; } Memory status after executing the statement int temp; In swap: 0xbffb361c: temp = ? 0xbffb3628: x = 0xbffb3644 --------- | 0xbffb362c: y = 0xbffb3640 ---- | *x | | In main: |*y | | | 0xbffb3640: y = 2 <----------- | | 0xbffb3644: x = 1 <---------------- CSC180 Fall 2008, University of Toronto 2
Background image of page 3

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

View Full Document Right Arrow Icon
Memory status after executing the statement *y = temp; In swap: 0xbffb361c: temp = 1 0xbffb3628: x = 0xbffb3644 --------- | 0xbffb362c: y = 0xbffb3640 ---- | *x | | In main: |*y | | | 0xbffb3640: y = 1 <----------- | | 0xbffb3644: x = 2 <---------------- Pointer arguments enable a callee function to modify objects from the
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 12

LEC20081010 - Introduction to Computer Programming CSC180...

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

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