In order to aect the actual value of arguments a and

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: •  See next example… 7 Pointers and Addresses (cont’d) •  Example: int x = 1, y = 2, z[10]; int *ip; /* ip is a pointer to int */ ip = &x; y = *ip; *ip = 0; ip = &z[0]; /* /* /* /* ip now points to x */ y is now 1 */ x is now 0 */ ip now points to z[0] */ 8 Pointers and Func1on Arguments •  Since C passes arguments to func1ons by value, there is no direct way to alter a variable in the calling func1on. Example: swap(a,b); /* will not swap */ … void swap(int x, int y){ int temp; temp = x; x = y; y = temp; } 9 Pointers and Func1on Arguments (cont’d) •  The call by value cannot affect the value of the arguments a and b because the func1on only swaps copies of a and...
View Full Document

This note was uploaded on 10/07/2012 for the course ENG 2sh4 taught by Professor Doyle during the Fall '12 term at McMaster University.

Ask a homework question - tutors are online