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: ment 0 of array y, or py contains the address of y[0]. py: y[0] y[1] y[2] y[3] y[4] y[5] y[6] y[7] y[8] y[9] y: The assignment x = *py; will assign the contents of y[0] into x. 16 Pointers and Arrays (cont’d) • Pointer arithmeCc operaCons: – Now, since py points to a parCcular element in array y (y[0]), then py+1 will point to the next element in the array. • py+i will point to i elements a_er py • py-i will point to i elements before py • Thus, if py points to y[0], then *(py+1) refers to the contents of y[1]. 17 Pointers and Arrays (cont’d) • Regardless of the type or size of the variables in array y, when we add i to a pointer (e.g. py +i), we point to the i ­th object beyond py. • Pointer notaCon and array notaCon: int i, *px, x = {4,5,9}; int i, *px, x = {4,5,9}; int sum = 0; int sum = 0; px = x; px = x; for(i=0; i < 3; i++) for(i=0; i < 3;...
View Full Document

This document was uploaded on 03/10/2014 for the course ENGINEER 2sh4 at McMaster University.

Ask a homework question - tutors are online