|
|
|
|
|
by SidiousL
2720 days ago
|
|
The actual principle behind the C type declarations is "declaration follows use". Let me explain what this means. Take this declaration int *pi;
Means that when I dereference the variable pi, I get an int. This also explains why int *pi, i;
declares `pi` as a pointer to `int` and `i` as an `int`. From this point of view it makes sense stylistically to put * near the variable.Declaration of array types is similar. For example, int arr[10];
means that when I take an element of `arr`, I obtain an `int`. Hence, `arr` is an array of ints.Pointers to functions work the same way. For example, int (*f)(char, double);
means that if I dereference the variable `f` and I evaluate it on a `char` and on a `double`, then I get an `int`. Hence, the type of `f` is "pointer to function which takes as arguments a char and a double and returns an int". |
|