cs lecture nov 1

cs lecture nov 1 - sum an array with a pointer int*a=int a...

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

View Full Document Right Arrow Icon
cs lecture nov 1 Pointers (ch 11/12) 0[ ] 1[ ] 2[ ] 3[ ] 4[ ] .. Pointer Arithmetic C supports 3 operations: -adding an integer to a pointer -subtracting an integer from a pointer -subtracting one pointer from another (of same type) 0[ ] 1[ ] 2[ ] 3[ ] 4[ ] .. 2 p ->P ->p [][][][][][][][][] q int a[8],*p,*q,*I; p=&a[2]; q=p+3; p+=4 subtracting pointers: p=q-3 i=q-p; /* 3 */ i=p-q/*-3*/ comparing pointers p>q p>=q p<q p<=q, p==q, p!=q
Background image of page 1

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

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: sum an array with a pointer int*a=int a int sum (int a, int n) { int *p,total=0; for(p=a;p<a+n;p++) total+=*p; return total; } a p Null Pointer-pointer to nothing, value is 0. int *p=(int*)0; “cast” of zero to be a pointer to an int Struct foo *r = (struct foo*)0; if(p!=(int*)0) { .. } or if(p) { .. } Dynamic Storage...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

cs lecture nov 1 - sum an array with a pointer int*a=int a...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online