Hello,

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!

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.

OK :)
I'm relaxed now :)

Thanks!

NP. Glad to help clear your mind - I use a nice Scotch Whiskey to do that! :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.