Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   about char pointer (http://www.velocityreviews.com/forums/t438633-about-char-pointer.html)

chellappa 07-06-2005 01:22 PM

about char pointer
 
hi ,
please explain me , char pointer , char Array, char ,string...
i have some many confussion about this...
please clarify to me..
i need some example about this program
by
chellappa.ns


Chris Dollin 07-06-2005 01:38 PM

Re: about char pointer
 
chellappa wrote:

> please explain me , char pointer , char Array, char ,string...


A decent book on C will explain all this, and be faster than
drip-feeding via Usenet. But:

A `char pointer` is a pointer that points to characters.
A `char array` is an array whose elements are characters.
A `char` is a value which is/represents a character.
A `string` is a sequence of characters terminated by a
null (== 0) character.

[A `sequence of characters` is a contiguous slice out of an
array or mallocated store.]

--
Chris "electric hedgehog" Dollin
It's called *extreme* programming, not *stupid* programming.

chellappa 07-06-2005 01:48 PM

Re: about char pointer
 
please give some examples


Mike Wahler 07-06-2005 02:10 PM

Re: about char pointer
 

"chellappa" <N.Chellappa@gmail.com> wrote in message
news:1120657680.190317.231520@z14g2000cwz.googlegr oups.com...
> please give some examples


Please preserve context when posting. Thank you.

Please get a textbook. You won't get far without
one.


"Chris Dollin" <kers@hpl.hp.com> wrote in message
news:dagmtd$lrl$1@malatesta.hpl.hp.com...
> chellappa wrote:
>
>> please explain me , char pointer , char Array, char ,string...

>
> A decent book on C will explain all this, and be faster than
> drip-feeding via Usenet. But:
>
> A `char pointer` is a pointer that points to characters.
> A `char array` is an array whose elements are characters.
> A `char` is a value which is/represents a character.
> A `string` is a sequence of characters terminated by a
> null (== 0) character.
>
> [A `sequence of characters` is a contiguous slice out of an
> array or mallocated store.]


"chellappa" <N.Chellappa@gmail.com> wrote in message
news:1120657680.190317.231520@z14g2000cwz.googlegr oups.com...
> please give some examples


char *p; /* 'char pointer' (a.k.a. 'Pointer to char'). */
/ * can represent address of a type 'char' object */

char a[10]; /* 'char array' (a.k.a. 'array of char'). */
/* can store ten type 'char' objects at */
/* contiguous memory locations */

char c; /* a type 'char' object. Can represent any one */
/* of the values of the execution character set */

char s[10] = "Hello" ; /* 'char array' (a.k.a. 'array of char'). */
/* The first six elements of the array */
/* (s[0] through s[5] inclusive) comprise */
/* a 'string' */


-Mike



Frank Mikkelsen 07-06-2005 06:47 PM

Re: about char pointer
 

"Mike Wahler" <mkwahler@mkwahler.net> skrev i en meddelelse
news:YCRye.13635$jX6.12659@newsread2.news.pas.eart hlink.net...
>
> "chellappa" <N.Chellappa@gmail.com> wrote in message
> news:1120657680.190317.231520@z14g2000cwz.googlegr oups.com...
>> please give some examples

>
> Please preserve context when posting. Thank you.
>
> Please get a textbook. You won't get far without
> one.
>
>
> "Chris Dollin" <kers@hpl.hp.com> wrote in message
> news:dagmtd$lrl$1@malatesta.hpl.hp.com...
>> chellappa wrote:
>>
>>> please explain me , char pointer , char Array, char ,string...

>>
>> A decent book on C will explain all this, and be faster than
>> drip-feeding via Usenet. But:
>>
>> A `char pointer` is a pointer that points to characters.
>> A `char array` is an array whose elements are characters.
>> A `char` is a value which is/represents a character.
>> A `string` is a sequence of characters terminated by a
>> null (== 0) character.
>>
>> [A `sequence of characters` is a contiguous slice out of an
>> array or mallocated store.]

>
> "chellappa" <N.Chellappa@gmail.com> wrote in message
> news:1120657680.190317.231520@z14g2000cwz.googlegr oups.com...
>> please give some examples

>
> char *p; /* 'char pointer' (a.k.a. 'Pointer to char'). */
> / * can represent address of a type 'char' object */
>
> char a[10]; /* 'char array' (a.k.a. 'array of char'). */
> /* can store ten type 'char' objects at */
> /* contiguous memory locations */
>
> char c; /* a type 'char' object. Can represent any one */
> /* of the values of the execution character set */
>
> char s[10] = "Hello" ; /* 'char array' (a.k.a. 'array of char'). */
> /* The first six elements of the array */
> /* (s[0] through s[5] inclusive) comprise */

wrong !! the: char s[10] = "Hello" assign 7 elements, donīt forget the zero
termination of the string at position
s[7]
> /* a 'string' */
>
>
> -Mike
>
>




Martin Ambuhl 07-06-2005 07:08 PM

Re: about char pointer
 
Frank Mikkelsen wrote:
> "Mike Wahler" <mkwahler@mkwahler.net> skrev i en meddelelse
> news:YCRye.13635$jX6.12659@newsread2.news.pas.eart hlink.net...


>>char s[10] = "Hello" ; /* 'char array' (a.k.a. 'array of char'). */
>> /* The first six elements of the array */
>> /* (s[0] through s[5] inclusive) comprise */

>
> wrong !! the: char s[10] = "Hello" assign 7 elements, donīt forget the zero
> termination of the string at position
> s[7]


Please explain why 5, the strlen("Hello"), + 1 for the terminating '\0'
gives 7.

When you assert that 5+1=7 and label 5+1=6 as "wrong !!", you have an
obligation to expound on your new theory of arithmetic.

Kevin J. Phillips 07-06-2005 07:11 PM

Re: about char pointer
 
Frank Mikkelsen wrote:
>> char s[10] = "Hello" ; /* 'char array' (a.k.a. 'array of char'). */
>> /* The first six elements of the array */
>> /* (s[0] through s[5] inclusive) comprise */

> wrong !! the: char s[10] = "Hello" assign 7 elements


The prior poster is correct:
s[0] = 'H'
s[1] = 'e'
s[2] = 'l'
s[3] = 'l'
s[4] = 'o'
s[5] = '\0'

That is 6 characters.

> donīt forget the zero termination of the string at position s[7]


If you were correct, and "Hello" took seven elements, then s[0]...s[5]
would contain the printable characters and s[6] (the 7th element of the
array), would contain the zero-termination character.


Mike Wahler 07-06-2005 07:53 PM

Re: about char pointer
 

"Frank Mikkelsen" <5034590m001@stofanet.dk> wrote in message
news:42cc272e$0$21463$ba624c82@nntp06.dk.telia.net ...
>
> "Mike Wahler" <mkwahler@mkwahler.net> skrev i en meddelelse
> news:YCRye.13635$jX6.12659@newsread2.news.pas.eart hlink.net...
>>
>> "chellappa" <N.Chellappa@gmail.com> wrote in message
>> news:1120657680.190317.231520@z14g2000cwz.googlegr oups.com...
>>> please give some examples

>>
>> Please preserve context when posting. Thank you.
>>
>> Please get a textbook. You won't get far without
>> one.
>>
>>
>> "Chris Dollin" <kers@hpl.hp.com> wrote in message
>> news:dagmtd$lrl$1@malatesta.hpl.hp.com...
>>> chellappa wrote:
>>>
>>>> please explain me , char pointer , char Array, char ,string...
>>>
>>> A decent book on C will explain all this, and be faster than
>>> drip-feeding via Usenet. But:
>>>
>>> A `char pointer` is a pointer that points to characters.
>>> A `char array` is an array whose elements are characters.
>>> A `char` is a value which is/represents a character.
>>> A `string` is a sequence of characters terminated by a
>>> null (== 0) character.
>>>
>>> [A `sequence of characters` is a contiguous slice out of an
>>> array or mallocated store.]

>>
>> "chellappa" <N.Chellappa@gmail.com> wrote in message
>> news:1120657680.190317.231520@z14g2000cwz.googlegr oups.com...
>>> please give some examples

>>
>> char *p; /* 'char pointer' (a.k.a. 'Pointer to char'). */
>> / * can represent address of a type 'char' object */
>>
>> char a[10]; /* 'char array' (a.k.a. 'array of char'). */
>> /* can store ten type 'char' objects at */
>> /* contiguous memory locations */
>>
>> char c; /* a type 'char' object. Can represent any one */
>> /* of the values of the execution character set */
>>
>> char s[10] = "Hello" ; /* 'char array' (a.k.a. 'array of char'). */
>> /* The first six elements of the array */
>> /* (s[0] through s[5] inclusive) comprise */

> wrong !! the: char s[10] = "Hello" assign 7 elements,


Really? Please explain.

(BTW that definition dos not 'assign' anything, it
*initializes* the first six characters of the array.
Initialization and assigment are not the same thing.)


> donīt forget the zero termination of the string at position
> s[7]


I did not forget about the terminator, but it's location
is s[5]. None of s[6] through s[9] have been initialized or
assigned a valid value.

-Mike



Robert Gamble 07-06-2005 08:29 PM

Re: about char pointer
 
Mike Wahler wrote:
> "Frank Mikkelsen" <5034590m001@stofanet.dk> wrote in message
> news:42cc272e$0$21463$ba624c82@nntp06.dk.telia.net ...
> >
> > "Mike Wahler" <mkwahler@mkwahler.net> skrev i en meddelelse
> > news:YCRye.13635$jX6.12659@newsread2.news.pas.eart hlink.net...
> >>
> >> "chellappa" <N.Chellappa@gmail.com> wrote in message
> >> news:1120657680.190317.231520@z14g2000cwz.googlegr oups.com...
> >>> please give some examples
> >>
> >> Please preserve context when posting. Thank you.
> >>
> >> Please get a textbook. You won't get far without
> >> one.
> >>
> >>
> >> "Chris Dollin" <kers@hpl.hp.com> wrote in message
> >> news:dagmtd$lrl$1@malatesta.hpl.hp.com...
> >>> chellappa wrote:
> >>>
> >>>> please explain me , char pointer , char Array, char ,string...
> >>>
> >>> A decent book on C will explain all this, and be faster than
> >>> drip-feeding via Usenet. But:
> >>>
> >>> A `char pointer` is a pointer that points to characters.
> >>> A `char array` is an array whose elements are characters.
> >>> A `char` is a value which is/represents a character.
> >>> A `string` is a sequence of characters terminated by a
> >>> null (== 0) character.
> >>>
> >>> [A `sequence of characters` is a contiguous slice out of an
> >>> array or mallocated store.]
> >>
> >> "chellappa" <N.Chellappa@gmail.com> wrote in message
> >> news:1120657680.190317.231520@z14g2000cwz.googlegr oups.com...
> >>> please give some examples
> >>
> >> char *p; /* 'char pointer' (a.k.a. 'Pointer to char'). */
> >> / * can represent address of a type 'char' object */
> >>
> >> char a[10]; /* 'char array' (a.k.a. 'array of char'). */
> >> /* can store ten type 'char' objects at */
> >> /* contiguous memory locations */
> >>
> >> char c; /* a type 'char' object. Can represent any one */
> >> /* of the values of the execution character set */
> >>
> >> char s[10] = "Hello" ; /* 'char array' (a.k.a. 'array of char'). */
> >> /* The first six elements of the array */
> >> /* (s[0] through s[5] inclusive) comprise */

> > wrong !! the: char s[10] = "Hello" assign 7 elements,

>
> Really? Please explain.
>
> (BTW that definition dos not 'assign' anything, it
> *initializes* the first six characters of the array.
> Initialization and assigment are not the same thing.)
>
>
> > donīt forget the zero termination of the string at position
> > s[7]

>
> I did not forget about the terminator, but it's location
> is s[5]. None of s[6] through s[9] have been initialized or
> assigned a valid value.


Actually, s[6] through s[9] *have* been initialized to '\0'.

Robert Gamble


Flash Gordon 07-06-2005 09:21 PM

Re: about char pointer
 
Mike Wahler wrote:
> "Frank Mikkelsen" <5034590m001@stofanet.dk> wrote in message
> news:42cc272e$0$21463$ba624c82@nntp06.dk.telia.net ...
>
>>"Mike Wahler" <mkwahler@mkwahler.net> skrev i en meddelelse
>>news:YCRye.13635$jX6.12659@newsread2.news.pas.ea rthlink.net...


<snip>

>>>char s[10] = "Hello" ; /* 'char array' (a.k.a. 'array of char'). */
>>> /* The first six elements of the array */
>>> /* (s[0] through s[5] inclusive) comprise */

>>
>>wrong !! the: char s[10] = "Hello" assign 7 elements,

>
> Really? Please explain.
>
> (BTW that definition dos not 'assign' anything, it
> *initializes* the first six characters of the array.
> Initialization and assigment are not the same thing.)
>
>>donīt forget the zero termination of the string at position
>>s[7]

>
> I did not forget about the terminator, but it's location
> is s[5]. None of s[6] through s[9] have been initialized or
> assigned a valid value.


Actually, the entire array is initialised, with the elements not
specified by the string literal being initialised to 0.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.


All times are GMT. The time now is 01:31 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.