# L07 - CME/Energy 211 Margot Gerritsen Shela Aboud Emmet...

This preview shows pages 1–8. Sign up to view the full content.

CME/Energy 211 Margot Gerritsen Shela Aboud Emmet Caulfield

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Lecture Overview • Pointers • Functions • Recursion
2D Array Address in Memory 21 20 19 18 17 16 15 14 13 12 x[0][0] x[0][1] x[0][2] x[0][3] x[0][4] x[1][0] x[1][1] x[1][2] x[1][3] x[1][4] 20 16 14 15 17 21 19 18 13 12 x[0][0] x[0][1] x[0][2] x[0][3] x[0][4] x[1][0] x[1][1] x[1][2] x[1][3] x[1][4] First row Second row int x[2][5]={0,0}; int I, j,k; //rows for(i=0;i<2;i++) { //columns for(j=0,k=10;j<5;j++,k++) { x[i][j]=k; } } x x+1 x+2 x+3 x+4 x+5 x+6 x+7 x+8 x+9

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Accessing Array Address 6 7 8 9 10 x[0] x[1] x[2] x[3] x[4] int x[5]={0}; int j,k; for(j=0,k=10;j<5;j++,k++) x[j]=k; x x+1 x+2 x+3 x+4 x[N] is the value of the N th element of the array x+N is the memory address of the Nth element *(x+N) is also the value of Nth element of the array &x[N] is also the memory address of the Nth element
Pointers < type > * < varname > A pointer is a variable that holds an memory address. The memory address is the location of another object in memory Pointer operators: & - unary operator that returns the memory address of its operand * - unary operator that returns the value located in a memory address (the complement of ) int *p

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Pointer Example 6 7 8 9 10 x[0] x[1] x[2] x[3] x[4] x x+1 x+2 x+3 x+4 int x[5]={0}; int *p; int j,k; for(j=0,k=10;j<5;j++,k++) x[j]=k; p=&x[1]; printf(“%d\n”,*p); p
Example - Pointers to Pointers

This preview has intentionally blurred sections. Sign up to view the full version.

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

{[ snackBarMessage ]}

### Page1 / 22

L07 - CME/Energy 211 Margot Gerritsen Shela Aboud Emmet...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online