------------------------------------------------------------ Topic 1: Pointers ( Review ) int a,b,c; int *p1, *p2, *p3; b = 100; p1 = &c; /* p1 points to c */ p3 = p1; /* p3 points to c also */ *p3 = 4; /* this sets c to 4 */ a = *p3; /* sets a to 4 */ p2 = &b; /* p2 points to b */ *p3 = *p2; /* same as: c = b; */ a = &c; /* don't do this */ c = p1; /* don't do this */ p2 = b; /* don't do this */ ------------------------------------------------------------ Topic 2: The "break" statement in loops * Example: a function to compare 1 array to another. Returns: * 1 if identical * 0 if not (Assumes both arrays have the same size) int arrayComp (int list1[], int list2[], int n) { int i; int result = 1; for (i = 0; i < n; i++) { if (list1[i] != list2[i]) { result = 0; break; /* exit the loop: no need to continue */ } } return(result); * alternate solution, with no break: int i; int result = 1; int stop = 0; for (i = 0; i < n && stop==0; i++) { if (list1[i] != list2[i]) { result = 0; stop = 1; } } return(result); * Using "break" makes the code a little cleaner, a little easier to read. * break can be used in any type of loop: For, while, do-while ------------------------------------------------------------ Topic 3: 2D Arrays Consider a function that computes the sum of all the values of the elements on the *perimeter* (outer edges) of a square 2-D array with 10 elements per side. The return value is that sum. Using the comments as a guide, please add statements to complete the function below. Please read all the comments first. You can declare more variables if you want to, but you don't have to. int addperim(int checkers[][10]) { int row, col; int sum; /* Compute the sum of the elements along the top edge. */ /* Add to "sum" all the values of the elements along the right edge. */ /* Add to "sum" all the values of the elements along the bottom edge. */ /* Add to "sum" all the values of the elements along the left edge. */ /* Some of the elements have been added twice! To compensate, */ /* subtract the value of each of these elements from "sum". */ return(sum); }