How to read complex pointers in C Programming?
Assign the priority to the pointer declaration considering precedence and associative according to following table.
Operator | Precedence | Associative |
(),[] | 1 | Left to right |
*, identifier | 2 | Right to left |
Data type | 3 |
Where:
() : This operator behaves as function operator. [] : This operator behaves as array subscription operator. * : This operator behaves as pointer operator. Identifier : it is name of pointer variable. Data type : Data types also includes modifier (like signed int, long double etc.) |
How to read following pointer?
char (* ptr)[3] |
- () and [] enjoys equal precedence. So rule of associative will decide the priority. Its associative is left to right So first priority goes to ().
- Inside the bracket * and ptr enjoy equal precedence. From rule of associative (right to left) first priority goes to ptr and second priority goes to *.
- Assign third priority to [].
- Since data type enjoys least priority so assign fourth priority to char.
