Can someone help me understand what is (if it is) the difference between string* myStr and string *myStr?
Or any other type of definitions like that: int* myValue vs int *myValue, char* myChar vs char *myChar.
The position of the "star" is confusing me. I only used pointers like this: int *myInt.
I've also seen the star in the middle int * myInt.

I tried google first, but shows a lot of non-related stuff.

Thank you!

3 Years
Discussion Span
Last Post by rubberman

There is absolutely no difference between the two. Personally, I prefer int* var because it keeps the variable name clean and the type definition together. But this is merely a matter of personal preference, i.e., it's esthetics. But functionally, it makes no difference at all.


I agree with Mike that the preferable construct is int* var - indicating that it is an integer pointer, which is an actual type. Moving the * to either next to the variable name, or between the int and variable name as your last example shows, kind of obfuscates that distinction.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.