Originally Posted by
narniat
But I'm almost sure that C is not specific about the symbol of a pointer-to-int type as it is about other types like int, char, etc.
Compile and run this program:
Code:
#include <stdio.h>
int main(void)
{
printf("A pointer to int is %zu bytes in size.\n", sizeof(int*));
return 0;
}
Originally Posted by
narniat
So (in my humble opinion), this is not a type symbol in C: int*.
There is no such thing as a "type symbol" in C, unless you mean type name, but int* is indeed a type name, hence you can use it (when parenthesized) with sizeof.
Originally Posted by
narniat
It's just a combination of two symbols together which indicates a pointer-to-int type(I may be wrong).
Every pointer type is a derived type, and by saying "indicates a pointer-to-int type", you have just described what a name of a type is, in particular, the name of the type that is known in English as pointer to int. In C, this is int*, i.e., int* is a type name, and this type name indicates (or identifies) the pointer-to-int type. You can say "it's just a combination of two symbols", but likewise int is just a combination of three symbols together which indicates an integer type. It so happens that because the pointer to int type is derived from this integer type, its type name is constructed from the type name of this integer type, i.e., int* is derived from int. It doesn't mean that int is a type name but int* isn't; they are both type names.
Originally Posted by
narniat
Otherwise `int* ap1, ap2, ap3` should have worked the same as `int a, b, c` does.
(...)
So when you want to declare three of this type, you write: `int *ap1,*ap2,*ap3`.
The problem is that you're fixated on the notion that variables are always declared like this:
Code:
TYPENAME identifier0, identifier1, identifier2;
This is a good way to introduce how to declare variables to beginners, but it is actually not the whole truth. For example, suppose we want to declare a variable named p that is a pointer to an array of 2 ints, without using a typedef:
This is because of the grammar of C. Hence, when you make an error concerning such a pointer or such an array, you might see your compiler giving you error messages that refer to a type that looks like int(*)[2].