By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,609 Members | 3,812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,609 IT Pros & Developers. It's quick & easy.

char *fred; char * fred; char *fred; any difference?

P: n/a
Hello,

can anyone explain the difference between the above declarations and why
anyone would stray from the first.
Are the other 2 standard, couldnt find them in K&R2.

Thanks,
Hal.
Nov 14 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Hal Styli" <no_spam@all> writes:
can anyone explain the difference between the above declarations and why
anyone would stray from the first.
Are the other 2 standard, couldnt find them in K&R2.


I suppose you're referring to the subject of your article, which
is
char *fred; char * fred; char *fred; any difference?
These all have the same meaning, as does char*fred.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 14 '05 #2

P: n/a
On Fri, 16 Jan 2004 22:10:54 -0000, in comp.lang.c , "Hal Styli"
<no_spam@all> wrote:
Hello,

can anyone explain the difference between the above declarations
what "above" declarations??? There's no declarations in your post.

(In other words, don't put your question in the subject, put it in the
mail body. Not all mail readers display teh subject next to the body,

Anyway all three are identical. As is
char * fred;
because whitespace is totally immaterial in (most) C statements.
and why anyone would stray from the first.
C++ programmers prefer to attach the * to the type. C programmers to
the object. Either is acceptable.
Are the other 2 standard, couldnt find them in K&R2.


K&R is a C book, and the authors used their preferred style.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 14 '05 #3

P: n/a
Mark McIntyre wrote:
[...]
Anyway all three are identical. As is
char * fred;
because whitespace is totally immaterial in (most) C statements.
and why anyone would stray from the first.


C++ programmers prefer to attach the * to the type. C programmers to
the object. Either is acceptable.


In the case of a single variable, yes. Of course:

char *ptr,c;

is probably clearer than:

char* ptr,c;

But, the above are still identical in meaning, and it's mostly a
matter of personal preference. (Sort of like "where do I put the
braces for for/while/etc. statements?")

[...]

--

+---------+----------------------------------+-----------------------------+
| Kenneth | kenbrody at spamcop.net | "The opinions expressed |
| J. | http://www.hvcomputer.com | herein are not necessarily |
| Brody | http://www.fptech.com | those of fP Technologies." |
+---------+----------------------------------+-----------------------------+

Nov 14 '05 #4

P: n/a
Kenneth Brody wrote:
Mark McIntyre wrote:
[...]

C++ programmers prefer to attach the * to the type.
C programmers to the object. Either is acceptable.


In the case of a single variable, yes. Of course:

char *ptr,c;

is probably clearer than:

char* ptr,c;

But, the above are still identical in meaning, and it's mostly
a matter of personal preference. (Sort of like "where do I put
the braces for for/while/etc. statements?")


C programmers prefer "char *ptr" because, while " char *"
describes the type pointer to char, it can't be used for multiple
items due to Cs weird and wonderful declaration syntax. However
you can use (but often frowned upon as obfuscative):

typedef char *charptr;
charptr cp1, cp2, cp3;

which has a much different meaning for cp2 and cp3 than:

char * cp1, cp2, cp3;

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #5

P: n/a
Greetings.

In article <40**********@127.0.0.1>, Hal Styli wrote:
can anyone explain the difference between the above declarations and why
anyone would stray from the first.
Are the other 2 standard, couldnt find them in K&R2.


Many people prefer keeping the * next to the variable rather than the type,
as this avoids the implication that the * is distributive. However,
syntactically the position doesn't matter.

Regards,
Tristan

--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you
Nov 14 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.