In C++, if we want to declare multiple pointers, we would do something like this: int *a, *b, *c;
where we would have to put an asterisk *
in front of each of them. if i write this code: typedef int* ptr; ptr a,b,c;
? Will they all be pointers, or just a?
No, typedef isn't just a matter of text substitution (like a macro would be).
typedef int* ptr;
introduces a new name, "ptr", for the type int*
.
If you write
ptr a, b, c;
all of a, b, and c will have the same type, int*
.
Note that
const ptr p;
likewise isn't the same as
const int* p;
Since ptr
is a pointer type, the const
applies to the pointer; the equivalent is
int* const p;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With