





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






*ptr
*(ptr+2) (^) *(ptr+4)
Printing an array
for (int i=0;i<len;i++) printf( "[ %d ] = %d\n" , i , a[i] );
if ( *y1 > *y2 )
if ( *y1 >= *y2 )
if ( *y1 == *y2 )
Passing arrays
void PrintArray(int pnArray, int nLength) { for (int i=0; i < nLength; i++) cout << pnArray[i] << “ “; //pnArray++ }
int main() { int anArray[6] = { 6, 5, 4, 3, 2, 1 }; PrintArray(anArray, 6); }
//Prints 6 5 4 3 2 1
Pointers and 2D arrays
v[0][0] v[0][1] V[1][0] V[1][1]
v[0][0] v[0][0] v[0][0] v[0][0]
Logical layout
Actual layout
ptr
#include <stdio.h> int main() { *int r=2,c=4; int a1[2][4]={{1,2,3,4},{5,6,7,8}}; int ptr=a1,i,j; for (i=0;i<r;i++) for(j=0;j<c;j++) { printf( "a1[ %d ][ %d ] = %d\n",i ,j, (ptr+j+(ic)) ); } return 0; }
Pointers and 2D arrays