18 pointers and arrays contd regardless of the type or

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: times vr[i] = v1[i] + v2[i]; // sum v elements } 14 Pointers and Arrays •  Pointers and arrays have a close rela1onship •  Any opera1on that can be done using array subscrip1ng can be done using pointers. 15 Pointers and Arrays (cont’d) •  Recall the array declara1on int y[10]; /* declares an integer array with */ /* 10 elements */ y[0] y[1] y[2] y[3] y[4] y[5] y[6] y[7] y[8] y[9] y: •  Then if py is declared a pointer to an integer int *py; we can assign the pointer to an element of the array by py = &y[0]; 16 Pointers and Arrays (cont’d) •  The assignment py = &y[0]; sets py to point to element 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. 17 Pointers and Ar...
View Full Document

Ask a homework question - tutors are online