class: title # Pointers ## CSC 161 – February 3, 2026 --- # Agenda for Today 1. Department Events 2. Upcoming Work 3. Discussion 4. Lab 5. Wrap Up --- # Department Events ## CS Table: User Interface Design .indent[ Tuesday, February 3rd at noon in JRC 224C ] ## CS Extra: University of Iowa U2G Program .indent[ Wednesday, February 4th at noon in Noyce 2021 Learn about an MS program for Grinnell students at UI ] ## CS Extra: Summer MAP Opportunites in CS .indent[ Thursday, February 5th at 4:15pm on Noyce 3821 Learn about MAP offerings in CS and related fields ] You can find a complete list of token events and submit more at
. --- class: section blue # Upcoming Work --- # Week 2 Lab Report **Due:** Tonight by 10:00pm Submit your completed `rps.c` to gradescope. You only need to submit the final version after completing the functions lab. Make sure you follow the coding standards we discussed last week. --- # Week 3 Quiz As usual, we'll have a quiz on Thursday. The quiz will last 10 minutes, and could cover any of these new topics: 1. Pointers 2. Arrays and Strings These are tricky concepts, so I will try to keep the questions basic for our first quiz that includes them. --- # Homework: Yahtzee **Due:** Thursday, February 12th ## Questions _None so far_ -- If you need to work on the assignment from off campus you can access a MathLAN session by going to
. --- class: section blue # Discussion --- # Discussion: Pointers **Items for think, pair, share:** 1. What is a pointer? Give an explanation that would make sense to a CSC 151 student. 2. We declare a pointer variable like this: `int* p;` What values can we assign to a pointer variable? 3. What operations can we perform on a pointer variable? 4. What is one reason a program might use a pointer? --- # Box and Arrow Diagrams We can use box and arrow diagrams to understand programs that use pointers. We'll work through this example as a demonstration: ```c int x; x = 3; int* y; y = &x; *y = 4; ``` --- # Box and Arrow Diagrams Draw a box and arrow diagram for this code fragment: ```c int a = 3; int b = 5; int* c = &b; *c = 7; c = &a; b = *c; ``` --- # Box and Arrow Diagrams Draw a box and arrow diagram for this code fragment: ```c int i = 100; int* j = &i; int k = 31; int* l = &k; j = l; *j = 4; *l = 12; ``` --- # Box and Arrow Diagrams What happens when we add functions? Draw a box and arrow diagram for this code fragment: ```c void increment(int* x) { *x = *x + 1; } int main() { int a = 5; increment(&a); } ``` --- # Reading Questions Do you have any unanswered questions from the reading? --- class: section blue # Lab --- class: section blue # Wrap Up --- # Wrap Up ## Lab Work Submit the following work from today's lab with your weekly lab report: - Exercise A.3 (written responses only) - Exercise B.3 ## Need Help? Attend the mentor session on Wednesday from 7–9pm to practice this material. You can also visit evening tutors and stop by my office hours if you have any questions or concerns. ## Reading - **Arrays** (Beej's Guide to C Programming, Chapter 6) - **Strings** (Beej's Guide to C Programming, Chapter 7)