What is the most proper way to place asterisk? Why?
1) type* var;
2) type *var;
When declaring a pointer type, place the asterisk next to the type name. Although you generally should not declare multiple variables on a single line, if you do, the asterisk has to be included with each variable.
An int* is a pointer to an int , so int*& must be a reference to a pointer to an int . Similarly, int** is a pointer to a pointer to an int , so int**& must be a reference to a pointer to a pointer to an int .
The initializer is an = (equal sign) followed by the expression that represents the address that the pointer is to contain. The following example defines the variables time and speed as having type double and amount as having type pointer to a double .
It means that aPointer points to a char pointer.
It does not matter as far as you are declaring only one pointer. It is usually writen like in the second example (in the code I usually read/write) but for the compiler it's the same.
The trouble can come out if you are declaring more than one pointer. For example, this is not declaring two pointer, instead it declares one pointer and one var of type type.
type* var1, var2;
You need to do instead:
type* var1, *var2;
I prefer to use the * by the var always.
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