Page 172 - DCAP507_SYSTEM_SOFTWARE
P. 172

System Software




                    Notes          we're setting the initial value for ip3, which is where ip3 will point, so that initial value is a
                                   pointer. (In other words, the * in the declaration int *ip3 = &i; is not the contents-of operator, it's
                                   the indicator that ip3 is a pointer.)
                                   If you have a pointer declaration containing an initialization, and you ever have occasion to
                                   break it up into a simple declaration and a conventional assignment, do it like this:

                                          int *ip3;
                                          ip3 = &i;
                                   Don't write
                                          int *ip3;

                                          *ip3 = &i;
                                   or you'll be trying to mix oil and water again.
                                   Also, when we write
                                          int *ip;

                                   although the asterisk affects ip's type, it goes with the identifier name ip, not with the type int on
                                   the left. To declare two pointers at once, the declaration looks like
                                          int *ip1, *ip2;

                                   Some people write pointer declarations like this:
                                          int* ip;
                                   This works for one pointer, because C essentially ignores whitespace. But if you ever write
                                          int* ip1, ip2;       /* PROBABLY WRONG */

                                   it will declare one pointer-to-int ip1 and one plain int ip2, which is probably  not what you
                                   meant.
                                   What is all of this good for? If it was just for changing variables like i from 5 to 7, it would not
                                   be good for much. What it's good for, among other things, is when for various reasons we don't
                                   know exactly which variable we want to change, just like the bank didn't know exactly which
                                   club member it wanted to send the statement to.

                                   Pointer Variable

                                   Pointer variable is a variable which holds the address of another variable. This concept allows
                                   the indirect access to the objects. A variable can be declared as pointer variable and can point to
                                   the starting byte address of any data-type variable. Thus, the value associated with the pointer
                                   variables is not the content of the memory locations to which it points, but the memory address
                                   of that location.
                                   Following is the way to declare and refer a pointer type variable:
                                   C:

                                   Base-type * pointer -variable-identifier;
                                   The address of any variable can be got by preceding the variable name by an ampersand (& ).









          166                               LOVELY PROFESSIONAL UNIVERSITY
   167   168   169   170   171   172   173   174   175   176   177