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

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

View Full Document Right Arrow Icon
CME/Energy 211 Margot Gerritsen Shela Aboud Emmet Caulfield
Background image of page 1

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

View Full DocumentRight Arrow Icon
Lecture Overview • Pointers • Functions • Recursion
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
Example - Pointers to Pointers
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online