Public Group

Archived

This topic is now archived and is closed to further replies.

Pointer asterisk placement

This topic is 5231 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, I did a search on this but couldn''t find any results. I just want to know the difference between the following 2 statements or are they the same? Substitute the char for any type. char* c; char *c;

Share on other sites
they are the same. which you use is a matter of preference. you can also to this:

char * c;

-me

Share on other sites
This has been flamed many times over, but ultimately
char *c
is better because
 char* a,b,c,d
is NOT the same as
char *a, *b, *c, *d

[edited by - Kaezin on March 22, 2004 5:09:41 PM]

Share on other sites
I agree Kaezin,

The only time I use "char*" instead of "char *" is when its the data type of a function. Else, Any variables are always "char *" for me.
Example:

char* myFunction(char *a, char *b);

- [BDS]StackOverflow

Share on other sites
quote:
Original post by BlueDev
I agree Kaezin,

The only time I use "char*" instead of "char *" is when its the data type of a function. Else, Any variables are always "char *" for me.
Example:

char* myFunction(char *a, char *b);

- [BDS]StackOverflow

Thanks for your quick answers guys, this forum is awesome. Regarding using char* for a function: will char * not work for a function or is that just your preferred format?

Share on other sites

Q. will char * not work for a function or is that just your preferred format?

A. Just a preferred format. It's easier when you have preferences so when you look at your code things formulate faster than trying to figure out what this is, where it is, how it is, and etc...

Glad you are enjoying the boards There are some skilled programmers here (including myself ) that wont mind helping you out when you need.

If you ever feel that your post is not recieveing any replies, no worries, either no one is interested in the topic or the question is out of some of our league. Either way, I'll try replying with some sort of answer even if it isn't the best.

- [BDS]StackOverflow

[edited by - BlueDev on March 22, 2004 6:12:23 PM]

Share on other sites
quote:
Original post by Kaezin
... ultimately
char *c
is better because
 char* a,b,c,d
is NOT the same as
char *a, *b, *c, *d

However,
char *a;char *b;char *c;char *d;
is better than
char *a, *b, *c, *d;
so your argument is moot. Now, I''m not trying to incite a religious war. No!

Share on other sites
I always preferred char* x to char *x. Mostly it''s because I choose to define "pointer-ness" as an attribute of a type rather than a variable. That is, an int pointer is a different type than an int.

As for the char* a, b, c, d, well that has always annoyed me so I avoid that construction except for rare cases where I do fall back to char *a, *b, *c, *d.

Ultimately it''s a matter of preference. There is no functional or syntactic different between the two.

Share on other sites
quote:
Original post by Kaezin
 char* a,b,c,d
is NOT the same as
char *a, *b, *c, *d

People who code like that have larger style issues to worry about than where they put their asterisks.

Share on other sites
quote:
Original post by Promit
I always preferred char* x to char *x. Mostly it''s because I choose to define "pointer-ness" as an attribute of a type rather than a variable. That is, an int pointer is a different type than an int.

That makes sense, but then the counter-argument to that is arrays. Definitely you would consider "array-ness" to be part of the type of the variable, but the array notation goes after the variable name:

int array[5]

so you can''t always group all the "type" information in one place.

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 32
• 41
• 23
• 13
• 13
• Forum Statistics

• Total Topics
631741
• Total Posts
3001985
×