Hi,

Can anyone explain in detail what is the difference between int *a and int* a? Is there any difference between them?

Hi,

Can anyone explain in detail what is the difference between int *a and int* a? Is there any difference between them?

No difference.. But it is better do it 'int *a;' because of readability and is more understandable.

Eg: Suppose the statement is

int* a, b;

it is actually equivalent to

int *a;
int b;

not

int *a;
int *b

If we had written the original statement as

int *a,b;

this would have been more obvious to someone who reads it who is a new bie.

Comments
I agree

Hey Perry 31,
I recently was reading up on white space rules for C. From what I gathered, tokens such as variable names, function names, variable data type names, other important words in the language, when in contact with operators are naturally separated.

Because of the phenomenon being true that int *var; is syntactically equivalent to int* var;, int*var;, and int<any number spaces>*<any number spaces>var;,I would suffice it to say that the pointer is considered an operator, which would explain why the organization does not and will never have an effect on the functionality when you, I, or anyone else are programming.

Edited 6 Years Ago by Jmknight: n/a

Hey Perry 31,
I recently was reading up on white space rules for C. From what I gathered, tokens such as variable names, function names, variable data type names, other important words in the language, when in contact with operators are naturally separated.

Because of the phenomenon being true that int *var; is syntactically equivalent to int* var;, int*var;, and int<any number spaces>*<any number spaces>var;,I would suffice it to say that the pointer is considered an operator, which would explain why the organization does not and will never have an effect on the functionality when you, I, or anyone else are programming.

In otherwords, to boil down that long-winded post, the answer is like I said before, There is no difference.

This question has already been answered. Start a new discussion instead.