Basic Rules
Understand how to interpret complex pointer declarations in C by applying rules for operator precedence and the right-left reading approach. This lesson helps you read combined pointer, array, and function types accurately, improving your comprehension of C's derived data types.
We'll cover the following...
Introduction
We’ve already seen our fair share of declarations involving pointers, such as pointers to variables, pointers to arrays, and pointers to functions. Examples of such declarations are as follows:
int* ptr; //ptr is a pointer to int
int x[10]; //x is an array of 10 elements
void(*funcPtr)(int x); //func is a pointer to a function taking an int as argument and returning void
These alone are pretty straightforward to read, but when we start to combine them, reading them can become rather complex. We didn’t define any specific rules for reading them, but we can do it intuitively by looking at the definition.
On the other hand, we also saw declarations like the following:
char* x[10]; //x is an array of 10 pointers to char
void(*funcPtr[])(int); //funcPtr is an array of pointers to functions taking an int as argument ...