newbie: char* int and char *int

T

trey

Hello brilliant people of c.l.c. -

I have a question about pointer declarations. Is there a difference between
the following declarations, and if so - what is it ? :)

char* int;
char * int;
char *int;

The type doesn't have to be char particularly. I'm just wondering if the
placement of the asterick is seriously important. Seems like it probably
is, but in this little experimental program I just wrote involving
pointers, I tried the first and last declarations and there was no
difference. Of course, this could have been luck and there is something
undefined going on in the background, which is why I'm posting this ;).
And since I've seen them used in all three ways, I was curious.

Thanks for any info...
-trey
 
A

Artie Gold

trey said:
Hello brilliant people of c.l.c. -

I have a question about pointer declarations. Is there a difference between
the following declarations, and if so - what is it ? :)

char* int;
char * int;
char *int;

The type doesn't have to be char particularly. I'm just wondering if the
placement of the asterick is seriously important. Seems like it probably
is, but in this little experimental program I just wrote involving
pointers, I tried the first and last declarations and there was no
difference. Of course, this could have been luck and there is something
undefined going on in the background, which is why I'm posting this ;).
And since I've seen them used in all three ways, I was curious.


The placement of the `*' is irrelevant.
[Of course, none of the above will actually work, as `int' is a
reserved word.]

HTH,
--ag
 
J

Jirka Klaue

trey said:
I have a question about pointer declarations. Is there a difference between
the following declarations, and if so - what is it ? :)

char* int;
char * int;
char *int;

The number and positioning of spaces is different. ;-)
The 3 expressions have the same semantics, though. (If you
replace int by some allowed identifier name, of course.)

However, the notation could matter to the human reader.
Consider:

char* p, c; /* c is _not_ a char*, despite the notation! */
char *p, c; /* See? */

Jirka
 
I

Irrwahn Grausewitz

trey said:
Hello brilliant people of c.l.c. -

I have a question about pointer declarations. Is there a difference between
the following declarations, and if so - what is it ? :)

char* int;
syntax error
char * int;
sentax yrror
char *int;
sontyx orrer

See, there's absolutely no difference! :)

If your question was: what is the difference between

char* cp;
char * cp;
char *cp;

the answer still is: there is no difference, all are perfectly
legal in C and have the same meaning, though the last one is
(mostly) preferred for stylistic reasons.

Irrwahn
 
T

trey

Irrwahn said:
syntax error

sentax yrror

sontyx orrer

See, there's absolutely no difference! :)

Umm...I have no idea what I was thinking. I mean, I did it in the subject
line, AND all three declarations. My only morsel of an excuse is that I
was in the middle of watching Law and Order** with my wife while writing
it. :)
If your question was: what is the difference between

char* cp;
char * cp;
char *cp;

the answer still is: there is no difference, all are perfectly
legal in C and have the same meaning, though the last one is
(mostly) preferred for stylistic reasons.

Got it. Thanks for the info (to everyone else also). char *cp makes more
sense to me also, and Jirke Klaue gave a good example where it could be
confusing not to.


-trey

** A US tv drama about cops and lawyers - don't want to get flamed for
assuming anything about geography, and it appears you are in fact in
Germany, at least a .de location using Forte Agent German edition, Standard
- the name was also a clue, but I wouldn't want to be name-prejudiced. ;)
Of course I could be wrong about all of it :)
 
I

Irrwahn Grausewitz

trey said:
[...]I have no idea what I was thinking. I mean, I did it in the subject
line, AND all three declarations. My only morsel of an excuse is that I
was in the middle of watching Law and Order** with my wife while writing
it. :)
** A US tv drama about cops and lawyers - don't want to get flamed for
assuming anything about geography, and it appears you are in fact in
Germany, at least a .de location using Forte Agent German edition, Standard
- the name was also a clue, but I wouldn't want to be name-prejudiced. ;)
Of course I could be wrong about all of it :)

Nope, you are absolutely right, Mr. Holmes :)

Irrwahn
 
T

trey

Irrwahn said:
trey said:
[...]I have no idea what I was thinking. I mean, I did it in the subject
line, AND all three declarations. My only morsel of an excuse is that I
was in the middle of watching Law and Order** with my wife while writing
it. :)
** A US tv drama about cops and lawyers - don't want to get flamed for
assuming anything about geography, and it appears you are in fact in
Germany, at least a .de location using Forte Agent German edition,
Standard - the name was also a clue, but I wouldn't want to be
name-prejudiced. ;) Of course I could be wrong about all of it :)

Nope, you are absolutely right, Mr. Holmes :)

Irrwahn

Ha, well, at least I did something right tonight :). (or morning to you I
believe)

Cheers
trey
 
I

Irrwahn Grausewitz

trey said:
Ha, well, at least I did something right tonight :). (or morning to you I
believe)
Yup, 5:20am. Going to bed now, it's been a long night... |-)

See ya

Irrwahn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top