This might have been discussed before. But I couldn't find any reference so far. So thought to post it.
When we declare pointer (say of int type) we write,
int* pointer;
Where int*
is data type (And therefore we can do typedef int* PTR_TO_INT;
and then can declare variables of type PTR_TO_INT
)
But when we want to declare multiple pointers, why do we need to affix * to each of them?
int* pointer1, pointer2, pointer3; // Only first is pointer. Rest are integers
While in this case it's not same convention:
PTR_TO_INT pointer1, pointer2, pointer3; // All are pointers.
Example:
int _tmain(int argc, _TCHAR* argv[])
{
typedef int* PTR_MYINT;
PTR_TO_INT xyz, abc;
int* xyz1, abc1;
xyz = NULL;
abc = xyz; // Valid, as both are pointers
abc1 = xyz1; // Invalid, as abc1 is not pointer
return 0;
}