LEC20081010 - Introduction to Computer Programming October...

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 DocumentRight 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 DocumentRight 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.

This note was uploaded on 01/10/2011 for the course CSC 180 taught by Professor Na during the Fall '01 term at University of Toronto.

Page1 / 12

LEC20081010 - Introduction to Computer Programming October...

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