Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > about char pointer

Reply
Thread Tools

about char pointer

 
 
chellappa
Guest
Posts: n/a
 
      07-06-2005
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

 
Reply With Quote
 
 
 
 
Chris Dollin
Guest
Posts: n/a
 
      07-06-2005
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.
 
Reply With Quote
 
 
 
 
chellappa
Guest
Posts: n/a
 
      07-06-2005
please give some examples

 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      07-06-2005

"chellappa" <> wrote in message
news: 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" <> wrote in message
news:dagmtd$lrl$...
> 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" <> wrote in message
news: 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


 
Reply With Quote
 
Frank Mikkelsen
Guest
Posts: n/a
 
      07-06-2005

"Mike Wahler" <> skrev i en meddelelse
news:YCRye.13635$ hlink.net...
>
> "chellappa" <> wrote in message
> news: 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" <> wrote in message
> news:dagmtd$lrl$...
>> 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" <> wrote in message
> news: 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
>
>



 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      07-06-2005
Frank Mikkelsen wrote:
> "Mike Wahler" <> skrev i en meddelelse
> news:YCRye.13635$ 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.
 
Reply With Quote
 
Kevin J. Phillips
Guest
Posts: n/a
 
      07-06-2005
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.

 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      07-06-2005

"Frank Mikkelsen" <> wrote in message
news:42cc272e$0$21463$ ...
>
> "Mike Wahler" <> skrev i en meddelelse
> news:YCRye.13635$ hlink.net...
>>
>> "chellappa" <> wrote in message
>> news: 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" <> wrote in message
>> news:dagmtd$lrl$...
>>> 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" <> wrote in message
>> news: 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


 
Reply With Quote
 
Robert Gamble
Guest
Posts: n/a
 
      07-06-2005
Mike Wahler wrote:
> "Frank Mikkelsen" <> wrote in message
> news:42cc272e$0$21463$ ...
> >
> > "Mike Wahler" <> skrev i en meddelelse
> > news:YCRye.13635$ hlink.net...
> >>
> >> "chellappa" <> wrote in message
> >> news: 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" <> wrote in message
> >> news:dagmtd$lrl$...
> >>> 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" <> wrote in message
> >> news: 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

 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      07-06-2005
Mike Wahler wrote:
> "Frank Mikkelsen" <> wrote in message
> news:42cc272e$0$21463$ ...
>
>>"Mike Wahler" <> skrev i en meddelelse
>>news:YCRye.13635$ 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.
 
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
(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
char *fred; char * fred; char *fred; any difference? Ben Pfaff C Programming 5 01-17-2004 07:37 PM
The difference between char a[6] and char *p=new char[6] ? wwj C Programming 24 11-07-2003 05:27 PM
the difference between char a[6] and char *p=new char[6] . wwj C++ 7 11-05-2003 12:59 AM



Advertisments