Hi,

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

There is no difference -- just programmer preference.

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.

commented: I agree +0

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.

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.

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.