Re: chars
- From: user923005 <dcorbit@xxxxxxxxx>
- Date: Mon, 7 Jan 2008 12:35:15 -0800 (PST)
On Jan 7, 12:20 pm, "Bill Cunningham" <nos...@xxxxxxxxx> wrote:
OK this thing about chars. So a string and a char is two different
things. This is the way I'm understanding things:
char c; is actually a short or int
c is neither a short nor an int. It is a {usually} different sized
integer, and is {usually} smaller than short even though it does not
have to be. But your notion (I think) is that a char can be
considered a very small integer type and that is correct.
char *s; s is a pointer to a char and to be used for strings
It does not have to be used for strings. It could point to a single
character. It is simply the place to store the address of one or more
characters.
char foo[5]; is an array used to store so much info.
The array foo stores 5 characters, which could be a string if it were
zero terminated.
Do I sound like I'm getting it right now?
Not sure. A string (in C) is a pointer to an array {or an array} of
zero or more characters with a terminating zero.
So this is a string:
char *foo = "I am a string";
and this is a string:
char bar[4] = "123";
but this is not a string, it's just an array because it does not have
a terminating zero:
char barbad[4] = "1234";
and neither is this:
char badbar[3] = {'a', 'b', 'c'};
Does it seem clear?
.
- Prev by Date: Re: chars
- Next by Date: Re: chars
- Previous by thread: Re: chars
- Next by thread: Re: chars
- Index(es):
Relevant Pages
|