Page 136 - C-Language
P. 136

char *names[20];


        [] takes precedence over *, so the interpretation is: names is an array of size 20 of a pointer to char.


         char (*place)[10];


        In case of using parentheses to override the precedence, the * is applied first: place is a pointer to
        an array of size 10 of char.


         int fn(long, short);


        There is no precedence to worry about here: fn is a function taking long, short and returning int.


         int *fn(void);


        The () is applied first: fn is a function taking void and returning a pointer to int.


         int (*fp)(void);


        Overriding the precedence of (): fp is a pointer to a function taking void and returning int.


         int arr[5][8];


        Multidimensional arrays are not an exception to the rule; the [] operators are applied in left-to-right
        order according to the associativity in the table: arr is an array of size 5 of an array of size 8 of int.


         int **ptr;


        The two dereference operators have equal precedence, so the associativity takes effect. The
        operators are applied in right-to-left order: ptr is a pointer to a pointer to an int.



        Multiple Declarations




        The comma can be used as a separator (*not* acting like the comma operator) in order to delimit
        multiple declarations within a single statement. The following statement contains five declarations:

         int fn(void), *ptr, (*fp)(int), arr[10][20], num;


        The declared objects in the above example are:


            •  fn: a function taking void and returning int;
            •  ptr: a pointer to an int;
            •  fp: a pointer to a function taking int and returning int;
            •  arr: an array of size 10 of an array of size 20 of int;
            •  num: int.




        https://riptutorial.com/                                                                             112
   131   132   133   134   135   136   137   138   139   140   141