Pointer asterisk placement
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;
they are the same. which you use is a matter of preference. you can also to this:
char * c;
-me
char * c;
-me
This has been flamed many times over, but ultimately
[edited by - Kaezin on March 22, 2004 5:09:41 PM]
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]
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
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
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?
Hey MadKiwi,
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]
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]
quote:Original post by Kaezin
... ultimatelyis better becausechar *c
is NOT the same aschar* a,b,c,d
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!
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.
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.
quote:Original post by Kaezinis NOT the same aschar* a,b,c,d
char *a, *b, *c, *d
People who code like that have larger style issues to worry about than where they put their asterisks.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement