CSC161 2010F, Class 33: Pointers and Arrays Overview: * Fun with Prospies. * Questions on Exam 2. * Pointers and Arrays. * Your Questions. * Labs. Admin: * We may have propsies today. Yay! * Question from a prospective 161 student: What is the workload like in this class compared to 151? * EC for MD's Monday presentation. * EC for Saturday's Men's Soccer game. * EC for LoC truck. * Reading for Monday: K&R 5.3 and Appendix B. Send questions! * Are there questions on Exam 2. Bring them on Monday! Fun with Prospies * What is your name? * Why are you visiting this class? * [One question determined by the members of the class.] * What would you like to know from this class? Questions on Exam 2 * Do we have to use the debugger? * No. Printfs, careful analysis, and more are also useful ways of identifying why your code fails. Pointers and Arrays * There's not a lot of difference between pointers and arrays. int y; int x; int z; int a[10]; int *ip = &x; * You can often treat a pointer as an array printf ("%d", ip[0]); ip[0] = 5; * You can often treat an array as a pointer *a = 1; * a[i] = X is the same as *(a+i) = X; * Ways to distinguish arrays and pointers * You can declare the size of the chunk of memory an array requires. * You can change what a pointer points to Your Questions on the Arrays/Pointers Reading * What does *(a+1) mean? * The C compiler knows the type of thing that a points to. So when you increment by 1, it says "that's 1 THING, not 1 byte" * Can a pointer point to a pointer? If so, can you access the value by using multiple * commands? * Yes. A pointer to a pointer even has a traditional name: a Handle * Info in 5.9 or so. * In page 105 about the comparison between the pointers and arrays, what is the difference in the declaration of arrays and pointers? * Please explain (*t = *s) != '\0'. * I don't understand what the point of allocp and afree are. Can you just talk about them a little? * Could you provide some examples in class illustrating the situations where it would be prudent to use pointers in a program? Labs