Page 107 - 6437
P. 107

You can also use an array of pointers to character to store a list of strings as follows:
                          When the above code is compiled and executed, it produces the following result:

                 Value of names[0] = Zara Ali
                 #include <stdio.h>
                  Value of names[1] = Hina Ali
                 Value of names[2] = Nuha Ali
                 const int MAX = 4;
                 Value of names[3] = Sara Ali


                 int main ()

                 {

                    char *names[] = {
                                        "Zara Ali",
                                        "Hina Ali",

                                        "Nuha Ali",

                                        "Sara Ali",
                    };
                    int i = 0;


                    for ( i = 0; i < MAX; i++)

                    {
                        printf("Value of names[%d] = %s\n", i, names[i] );

                    }
                    return 0;

                 }


                          Pointer to Pointer
                          A pointer to a pointer is a form of multiple indirection, or a chain of pointers. Normally, a
                   pointer contains the address of a variable. When we define a pointer to a pointer, the first pointer
                   contains the address of the second pointer, which points to the location that contains the actual
                   value as shown below.



















                                                                                                     110
   102   103   104   105   106   107   108   109   110   111   112