473,796 Members | 2,603 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
5 2006
"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[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 14 '05 #2
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.c om/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
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
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********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 14 '05 #5
Greetings.

In article <40**********@1 27.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
14405
by: Rick | last post by:
Hi, This is probably piece of cake for you C gurus but it is giving me a headache. I'm still not really used with pointers and chars so many things are going wrong. Practicing makes wonders but the problem is that I don't have much time to practice. Ok, here's the question, how to reset a char array? I got this code : char test = "";
7
30391
by: Fred Nelson | last post by:
Hi: I'm more than a little confused with this question: I need to create a char type from the first letter in a string - for example: string mystring; char mychar;
4
1355
by: Fred Nelson | last post by:
Hi: Newby Question: I have the following code in a class library that performs a query on an SQL database and is returning a class that contains "locatestatus": if (p_locatestatus.Value != System.DBNull.Value) { rtrec.locatestatus = (char)p_locatestatus.Value; };
3
1104
by: Fred | last post by:
I have a String of bits -- "101011". I want to extract each bit in the string as a char and then use each extracted char in multiplication. The extraction part is easy (I think). How can I convert each char to an int so that I can use it for multiplication? Thanks.
6
38988
by: MattWilson.6185 | last post by:
Hello! I am trying to convert a char * to a LPWSTR, and I am going absolutly mad! I can't find anything besides typle L"string" Unfortunetaly I can't use that... basicaly the setup is callbackFromAnotherFunctionWhichMustBeOfChar(char* helpMe) { //...
13
1660
by: RoughRyde | last post by:
Hi all, I'm totally new to C and hava a problem how to handle different types of variables. I have a function which which you call by: double calcdiff(const char *old, const char *new) I have at start two doubles that I need to convert in order to call the
19
2131
by: arnuld | last post by:
i am trying to understand arrays and char. Stroustrup says, this a string literal: "this is a string literal" he says it is of type /const char/. he also says, because of keeping compatibilities with previous definitions of C & C++, it is also a CHAR POINTER a.k.a /char*/. however it is an error, which can not be caught at untill runtime, to modify a string literal using such pointer:
6
10678
by: newbarker | last post by:
Hello, This program doesn't work and provides me the errror message "error C2040: 'p' : 'std::string' differs in levels of indirection from 'const char *'": #include <string> int main() {
5
2982
by: Stuudent | last post by:
Hi! Is there possibility to read char* table word by word in C (not C++)? I'm learning C by writing simple HTTP Server on BSD sockets (just for fun). And I want to read info from HTTP header received from client. I get char table, and I have to read some information. Can you help me? I can post the whole code of server when I finish.
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10465
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10242
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9061
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5453
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4127
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.