about char pointer

Discussion in 'C Programming' started by chellappa, Jul 6, 2005.

  1. chellappa

    chellappa Guest

    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
     
    chellappa, Jul 6, 2005
    #1
    1. Advertising

  2. chellappa

    Chris Dollin Guest

    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.
     
    Chris Dollin, Jul 6, 2005
    #2
    1. Advertising

  3. chellappa

    chellappa Guest

    please give some examples
     
    chellappa, Jul 6, 2005
    #3
  4. chellappa

    Mike Wahler Guest

    "chellappa" <> wrote in message
    news:...
    > 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:...
    > 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
     
    Mike Wahler, Jul 6, 2005
    #4
  5. "Mike Wahler" <> skrev i en meddelelse
    news:YCRye.13635$...
    >
    > "chellappa" <> wrote in message
    > news:...
    >> 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:...
    >> 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
    >
    >
     
    Frank Mikkelsen, Jul 6, 2005
    #5
  6. Frank Mikkelsen wrote:
    > "Mike Wahler" <> skrev i en meddelelse
    > news:YCRye.13635$...


    >>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.
     
    Martin Ambuhl, Jul 6, 2005
    #6
  7. 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.
     
    Kevin J. Phillips, Jul 6, 2005
    #7
  8. chellappa

    Mike Wahler Guest

    "Frank Mikkelsen" <> wrote in message
    news:42cc272e$0$21463$...
    >
    > "Mike Wahler" <> skrev i en meddelelse
    > news:YCRye.13635$...
    >>
    >> "chellappa" <> wrote in message
    >> news:...
    >>> 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:...
    >>> 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
     
    Mike Wahler, Jul 6, 2005
    #8
  9. Mike Wahler wrote:
    > "Frank Mikkelsen" <> wrote in message
    > news:42cc272e$0$21463$...
    > >
    > > "Mike Wahler" <> skrev i en meddelelse
    > > news:YCRye.13635$...
    > >>
    > >> "chellappa" <> wrote in message
    > >> news:...
    > >>> 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:...
    > >>> 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
     
    Robert Gamble, Jul 6, 2005
    #9
  10. chellappa

    Flash Gordon Guest

    Mike Wahler wrote:
    > "Frank Mikkelsen" <> wrote in message
    > news:42cc272e$0$21463$...
    >
    >>"Mike Wahler" <> skrev i en meddelelse
    >>news:YCRye.13635$...


    <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.
     
    Flash Gordon, Jul 6, 2005
    #10
  11. chellappa

    CBFalconer Guest

    chellappa wrote:
    >
    > please give some examples


    Of what? of sums? 2+2 = 4; of products? 2 * 3 = 6

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
     
    CBFalconer, Jul 6, 2005
    #11
  12. chellappa

    CBFalconer Guest

    Robert Gamble wrote:
    > Mike Wahler wrote:
    >> "Frank Mikkelsen" <> wrote
    >>> "Mike Wahler" <> skrev
    >>>> "chellappa" <> wrote

    >

    .... 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, s[6] through s[9] *have* been initialized to '\0'.


    I doubt it. To argue it you have to first present a complete
    compilable source.

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
     
    CBFalconer, Jul 7, 2005
    #12
  13. chellappa

    Jack Klein Guest

    On Thu, 07 Jul 2005 01:10:37 GMT, CBFalconer <>
    wrote in comp.lang.c:

    > Robert Gamble wrote:
    > > Mike Wahler wrote:
    > >> "Frank Mikkelsen" <> wrote
    > >>> "Mike Wahler" <> skrev
    > >>>> "chellappa" <> wrote

    > >

    > ... 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, s[6] through s[9] *have* been initialized to '\0'.

    >
    > I doubt it. To argue it you have to first present a complete
    > compilable source.


    No, you don't, because neither the linkage nor the storage duration of
    the object in question have any effect on the truth of the statement.
    Any place in a C file where the definition:

    char s[10] = "Hello";

    ....is legal and valid, the effect of having any initializer present
    guarantees that all 10 characters are initialized. And it
    specifically guarantees that any for which there are insufficient
    initializers are default initialized with 0.

    6.7.8 P 21:
    "If there are fewer initializers in a brace-enclosed list than there
    are elements or members of an aggregate, or fewer characters in a
    string literal used to initialize an array of known size than there
    are elements in the array, the remainder of the aggregate shall be
    initialized implicitly the same as objects that have static storage
    duration."

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Jul 7, 2005
    #13
  14. chellappa

    CBFalconer Guest

    Jack Klein wrote:
    > CBFalconer <>
    >> Robert Gamble wrote:
    >>> Mike Wahler wrote:
    >>>> "Frank Mikkelsen" <> wrote
    >>>>> "Mike Wahler" <> skrev
    >>>>>> "chellappa" <> wrote
    >>>

    >> ... 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, s[6] through s[9] *have* been initialized to '\0'.

    >>
    >> I doubt it. To argue it you have to first present a complete
    >> compilable source.

    >
    > No, you don't, because neither the linkage nor the storage duration of
    > the object in question have any effect on the truth of the statement.
    > Any place in a C file where the definition:
    >
    > char s[10] = "Hello";
    >
    > ...is legal and valid, the effect of having any initializer present
    > guarantees that all 10 characters are initialized. And it
    > specifically guarantees that any for which there are insufficient
    > initializers are default initialized with 0.


    Consider my objection withdrawn. Thanks for the correction. All I
    can say is that I erred in the safe direction.

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
     
    CBFalconer, Jul 7, 2005
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wwj
    Replies:
    7
    Views:
    561
  2. wwj
    Replies:
    24
    Views:
    2,526
    Mike Wahler
    Nov 7, 2003
  3. Ben Pfaff
    Replies:
    5
    Views:
    482
    Tristan Miller
    Jan 17, 2004
  4. Steffen Fiksdal

    void*, char*, unsigned char*, signed char*

    Steffen Fiksdal, May 8, 2005, in forum: C Programming
    Replies:
    1
    Views:
    592
    Jack Klein
    May 9, 2005
  5. lovecreatesbeauty
    Replies:
    1
    Views:
    1,071
    Ian Collins
    May 9, 2006
Loading...

Share This Page