Pointer question?

Discussion in 'C Programming' started by rattan@cps.cmich.edu, Jul 31, 2006.

  1. Guest

    Assume the following codce (line numbers of reference only, compiler
    gcc-3.4):

    1 int a[3] = {2, 2, 3}, **ptr;
    2 int sumit(int **, int);

    calling sumit:

    3 sumit(&a, 3);
    or
    4 *ptr = a; sumit(ptr, 3);

    call on line 3 produces incompatible type pointers warning
    but on line 4 does not.

    So, what is the difference between the two calls?

    -ishwar
     
    , Jul 31, 2006
    #1
    1. Advertising

  2. Eric Sosman Guest

    wrote On 07/31/06 12:37,:
    > Assume the following codce (line numbers of reference only, compiler
    > gcc-3.4):
    >
    > 1 int a[3] = {2, 2, 3}, **ptr;
    > 2 int sumit(int **, int);
    >
    > calling sumit:
    >
    > 3 sumit(&a, 3);
    > or
    > 4 *ptr = a; sumit(ptr, 3);
    >
    > call on line 3 produces incompatible type pointers warning
    > but on line 4 does not.
    >
    > So, what is the difference between the two calls?


    This is Question 6.18 in the comp.lang.c Frequently
    Asked Questions (FAQ) list

    http://www.c-faq.com/

    --
     
    Eric Sosman, Jul 31, 2006
    #2
    1. Advertising

  3. On 31 Jul 2006 09:37:51 -0700, wrote:

    >Assume the following codce (line numbers of reference only, compiler
    >gcc-3.4):
    >
    >1 int a[3] = {2, 2, 3}, **ptr;
    >2 int sumit(int **, int);
    >
    >calling sumit:
    >
    >3 sumit(&a, 3);
    >or
    >4 *ptr = a; sumit(ptr, 3);


    While this may be correct syntactically, it invokes undefined
    behavior.

    >
    >call on line 3 produces incompatible type pointers warning
    >but on line 4 does not.
    >
    >So, what is the difference between the two calls?


    What is the type of a? What is the type of &a?


    Remove del for email
     
    Barry Schwarz, Aug 1, 2006
    #3
    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. Replies:
    10
    Views:
    704
    Chris Torek
    Feb 4, 2005
  2. jimjim
    Replies:
    16
    Views:
    843
    Jordan Abel
    Mar 28, 2006
  3. Replies:
    4
    Views:
    1,268
    Fred Zwarts
    Jul 2, 2009
  4. A
    Replies:
    7
    Views:
    639
  5. , India

    pointer to an array vs pointer to pointer

    , India, Sep 20, 2011, in forum: C Programming
    Replies:
    5
    Views:
    457
    James Kuyper
    Sep 23, 2011
Loading...

Share This Page