questions on pointers

Discussion in 'C Programming' started by JOhn, May 15, 2008.

  1. JOhn

    JOhn Guest

    can someone please post some complicated question on pointers??

    moreover while reading pointers I found out that there is a lot of
    difference between an arracy of intergers and an array of
    characters(string) ............. relating to
    pointers ................am i correct................the way pointers
    behave when they have a char array as an address and the way they
    behave when they have an integer array as an address ????

    please help as pointers is haunting me a lot ??? despite of being
    quite old to 'C'

    please help
     
    JOhn, May 15, 2008
    #1
    1. Advertising

  2. JOhn

    Lew Pitcher Guest

    In comp.lang.c, JOhn wrote:

    > can someone please post some complicated question on pointers??


    Not really. Depending on your POV, pointers are either trivially simple (and
    thus there are /no/ complicated questions) or impossibly hard (and
    thus /every/ question is a complicated question). For the trivially easy
    POV, I have no questions, and for the impossibly hard POV, any question you
    ask will be a complicated question. Such is life :)

    > moreover while reading pointers I found out that there is a lot of
    > difference between an arracy of intergers and an array of
    > characters(string) ............. relating to
    > pointers ................am i correct................the way pointers
    > behave when they have a char array as an address and the way they
    > behave when they have an integer array as an address ????


    No and yes. They behave exactly the same, conceptually.
    Increment a pointer to an object and it will point at the next object
    The /value/ of the pointer may differ with different objects, as different
    objects have different sizes.

    Thus, in both of the following code snippets
    char a[3], *p;
    p = &a[0] + 1;
    and
    int a[3], *p;
    p = &a[0] + 1;
    the pointer 'p' will point at a[1]

    However, the /value/ of p (that is, the "address") may differ, as int values
    are usually stored in bigger spaces than char values. Consequently
    int a[3], *ip;
    char *cp;
    ip = &a[0] + 1;
    cp = (char)&a[0] + 1;
    will usually result in ip and cp having different values.

    > please help as pointers is haunting me a lot ??? despite of being
    > quite old to 'C'
    >
    > please help


    --
    Lew Pitcher

    Master Codewright & JOAT-in-training | Registered Linux User #112576
    http://pitcher.digitalfreehold.ca/ | GPG public key available by request
    ---------- Slackware - Because I know what I'm doing. ------
     
    Lew Pitcher, May 15, 2008
    #2
    1. Advertising

  3. JOhn <> writes:
    > can someone please post some complicated question on pointers??
    >
    > moreover while reading pointers I found out that there is a lot of
    > difference between an arracy of intergers and an array of
    > characters(string) ............. relating to
    > pointers ................am i correct................the way pointers
    > behave when they have a char array as an address and the way they
    > behave when they have an integer array as an address ????
    >
    > please help as pointers is haunting me a lot ??? despite of being
    > quite old to 'C'


    The comp.lang.c FAQ is at <http://www.c-faq.com/>. Sections 4, 5, and
    6 cover pointers. Have you read them?

    Arrays of char and arrays of int behave essentially the same way with
    respect to pointers as any other array type. Pointer arithmetic
    operates in units of the size of the element type, 1 byte for pointers
    to char, sizeof(int) bytes for pointers to int. If you can tell us
    just what difference you're seeing, we can probably help clarify it
    for you.

    (Incidentally, using all lower case and long strings of '.' and '?'
    characters doesn't help the readability of your article.)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, May 15, 2008
    #3
  4. JOhn

    lee Guest

    On 5ÔÂ16ÈÕ, ÉÏÎç4ʱ52·Ö, JOhn <> wrote:
    > can someone please post some complicated question on pointers??
    >
    > moreover while reading pointers I found out that there is a lot of
    > difference between an arracy of intergers and an array of
    > characters(string) ............. relating to
    > pointers ................am i correct................the way pointers
    > behave when they have a char array as an address and the way they
    > behave when they have an integer array as an address ????
    >
    > please help as pointers is haunting me a lot ??? despite of being
    > quite old to 'C'
    >
    > please help


    you can read a book named Puzzle c.
     
    lee, May 17, 2008
    #4
    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. Phil
    Replies:
    1
    Views:
    671
    llewelly
    Sep 16, 2003
  2. muser
    Replies:
    3
    Views:
    784
    Ron Natalie
    Sep 18, 2003
  3. A
    Replies:
    3
    Views:
    479
    Alan Kelon
    Oct 29, 2003
  4. Marc Thrun
    Replies:
    15
    Views:
    883
    Tim Rentsch
    Oct 4, 2005
  5. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    732
Loading...

Share This Page