1
Announcements
Midterm next week Material covered up until June 18 (last week,
signals)
Allowed to have 1 cheat sheet No tutorial Come to class at 6 Test is 6:10 – 7:00 Assignment 3 is on the web site
Pointers about pointers
pointer is a memory address is 4 bytes like an unsigned int can address up to 2^32 bytes = 4 gb declaring a pointer allocates 4 bytes for the
pointer itself - that's it! char * ptr; gets(ptr);
will compile, but crash
Pointer type
pointers are typed char * pchar; vs. int * pint,
struct mystruct * pstruct;
similarity: all are 4 bytes difference: pchar++; //increment by 1 byte pint++; //increment by 4 bytes pstruct++; //increment by sizeof(mystruct)
Example
char * pchar; int * pint; struct mystruct * pstruct; int arry[3][3] = { {1,2,3}, {4,5,6}, {7,8,9}}; pchar = (char *)arry; pint=(int *)arry; pstruct=(struct mystruct *)arry; printf("pchar=%p,pint=%p,pstruct=%p\n",pchar,pint,pstruct); pchar+=1; pint+=1; pstruct+=1; printf("pchar=%p,pint=%p,pstruct=%p\n",pchar,pint,pstruct); pchar=0012FF50,pint=0012FF50,pstruct=0012FF50 pchar=0012FF51,pint=0012FF54,pstruct=0012FF58