CSC161 2010F, Class 31: Pointers Overview: * HW6 * More on Make * More on HW5 * Pointer and Memory Basics * Your Questions * Lab Admin: * Cool Theatre stuff on campus this week. * LoC Truck on Friday. * Reading for tomorrow: K&R 5.3-5.4. * Don't forget questions! * We'll go over some questions and issues on HW6. HW 6 * What modifiers do you have for variables? static and extern are two good ones. * Is Google our friend for finding out about macros? * Yes. As long as you spell correctly. * What should a Boolean function, such as is_prime, return? * An integer * 1 for "true" (or any positive number) * 0 for "false" * How do we build the Fibonacci sequence non-recursively F_prev = 0 F_current = 1 repeat lots of times F_next = F_prev + F_current F_prev = F_current F_current = F_next * Is there a remainder function? * Mod (%) should suffice HW 5 * Systematic checks of sorting involves building lots of permutations Make * Skipped for time issues Pointers * Operator: & (address-of) gives the address (location in memory) of a variable. ip = &x; * You need to be able to do interesting things with addresses. * Find out what value is stored at that address printf ("%d", *ip); * Change what is stored at that address *ip = ... * Variables of poitner type type *variable; int *ip; Your Questions * Couldn't you also return the new a and b instead of making swap a void functio NO. C only lets you return/assign one value at a time n? * In the swap routine example, are pointers the only way to make that function work? YES, if you restrict yourself to writing a function BUT a macro could work: #define SWAP(X,Y) { temp = X; X = Y; Y = temp; } swap (a[i++], b[j++]); * Could you explain the * operator? It seems clearly laid out on page 94, but I'm just not wrapping my head all the way around it. Other Questions * !! - the last command * !number - command number N (determine by history) * !text - the last command that began with text * !$ - the last item on the previous line mkdir /home/rebelsky/foo cd !$ * ^text^replacement Redoes the last command, replacing the FIRST INSTANCE of text with replacement