Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > newbie: char* int and char *int

Reply
Thread Tools

newbie: char* int and char *int

 
 
trey
Guest
Posts: n/a
 
      09-10-2003
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

 
Reply With Quote
 
 
 
 
Artie Gold
Guest
Posts: n/a
 
      09-10-2003
trey wrote:
> 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


--
Artie Gold -- Austin, Texas

 
Reply With Quote
 
 
 
 
Jirka Klaue
Guest
Posts: n/a
 
      09-10-2003
trey wrote:

> 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

 
Reply With Quote
 
Irrwahn Grausewitz
Guest
Posts: n/a
 
      09-10-2003
trey <(E-Mail Removed)> wrote:

>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

--
Computer: a million morons working at the speed of light.
 
Reply With Quote
 
trey
Guest
Posts: n/a
 
      09-10-2003
Irrwahn Grausewitz wrote:

> trey <(E-Mail Removed)> wrote:
>
>>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!


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

 
Reply With Quote
 
Irrwahn Grausewitz
Guest
Posts: n/a
 
      09-10-2003
trey <(E-Mail Removed)> wrote:
<SNIP>
>
>[...]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.

<SNIP>
>** 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
--
Computer: a million morons working at the speed of light.
 
Reply With Quote
 
trey
Guest
Posts: n/a
 
      09-10-2003
Irrwahn Grausewitz wrote:

> trey <(E-Mail Removed)> wrote:
> <SNIP>
>>
>>[...]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.

> <SNIP>
>>** 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

 
Reply With Quote
 
Irrwahn Grausewitz
Guest
Posts: n/a
 
      09-10-2003
trey <(E-Mail Removed)> wrote:
>Irrwahn Grausewitz wrote:
>> trey <(E-Mail Removed)> wrote:
>> <SNIP>
>>>** 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)
>

Yup, 5:20am. Going to bed now, it's been a long night... |-)

See ya

Irrwahn
--
Computer: a million morons working at the speed of light.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
int urldecode(char *src, char *last, char *dest) gert C Programming 20 02-16-2007 11:28 PM
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
int main(int argc, char *argv[] ) vs int main(int argc, char **argv ) Hal Styli C Programming 14 01-20-2004 10:00 PM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM



Advertisments