Basic Rules

Learn more about the type system used in C. Discover a simple process for understanding complex declarations.

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
...