HW 12: Indirect Rotate ----------------------------------------------------------------------------- REMINDERS ABOUT POINTERS: Variables of type "pointer-to-something" are memory cells, just as any variable is. And therefore they have addresses too. Consider: int *p; The variable p is a variable of type "pointer-to-int". We can express its address as: &p &p is the numerical RAM address of p, but what is the TYPE of &p? We know that given int x; the type of &x is "pointer-to-int" because &x is the address of an int. Similarly, given int *p; the type of &p is "pointer-to-pointer-to-int", because &p is the address of something that holds the address of an int! It is no more complicated than my giving you a note that tells you the location of a room whose door has another note that tells you the location of the room we will hold our class in. It is merely a second level of indirection. Give that &p above is a constant of type "pointer-to-pointer-to-int", how would we declare a variable of that same type? Here's how: int **pp; This is read, as usual, from right to left: pp is a pointer to a pointer to an int. (Each star in the declaration reads a "a pointer to a".) Given the declarations int **pp, *p, x; we can write: pp = &p; /* Now pp points to p */ /* and so *pp IS p */ Now, pp points to p. Suppose we want p to point to x. One way of accomplishing this then is: p = &x; But another way is *pp = &x; /* *pp and p are the same! */ That's because *pp is an ALIAS for p, since pp contains the address of p. So, given the code: int **pp, *p, x; pp = &p; /* Now pp points to p */ *pp = &x; /* Now p points to x */ we can say that pp is a pointer to a pointer to x! Suppose we want to put the value 17 into x. Each of the following at this point would work: x = 17; /* the obvious way */ *p = 17; /* works because p points to x */ **pp = 17; /* works because pp points to p which in turn points to x */ ----------------------------------------------------------------------------- THE ASSIGNMENT In this assignment, you are are to write a function called "irotate()" that has the following behavior: Given the following sample declarations and code: int a, b, c, *p, *q, *r; a = 17; b = 33; c = 88; p = &a; q = &b; r = &c; then the call irotate(&p,&q,&r); /* p is a pointer-to-int so */ /* &p is a pointer-to-pointer-to int */ results in a getting b's original value (33), b getting c's original value (88), and c getting a's original value (17). That is the vlaues of a,b,c are "rotated". In other words, irotate() RECEIVES THREE PARAMETERS, each of which is a pointer to a pointer to an int. The irotate() function ROTATES (rotates) the values of the three ints that these pointers are indirectly referring to. NOTE: Your function should be in a file called "irotate.c". This file should contain irotate() but should NOT contain a main() function. You should also prepare a header file (i.e. "include" file) called "irotate.h" that contains the prototype for the function irotate(). WHAT TO SUBMIT VIA TOTEACH: Just submit your source code: irotate.c and irotate.h Do NOT submit any other source code.