reference to a pointer

Discussion in 'C Programming' started by sam_cit@yahoo.co.in, Dec 17, 2006.

  1. Guest

    Hi Everyone,

    I just came to know about a declartion, namely reference to a pointer
    like the following,

    int *&p; //p is a reference to a pointer to an integer

    Is this valid only in C++ and not in C?

    and i also came to know that there is a difference between call by
    address and call by reference, can anyone tell me the exact difference?
     
    , Dec 17, 2006
    #1
    1. Advertising

  2. said:

    > Hi Everyone,
    >
    > I just came to know about a declartion, namely reference to a pointer
    > like the following,
    >
    > int *&p; //p is a reference to a pointer to an integer
    >
    > Is this valid only in C++ and not in C?


    Whether it is valid in C++ is a question for a C++ reference book. It is not
    valid in C.

    > and i also came to know that there is a difference between call by
    > address and call by reference, can anyone tell me the exact difference?


    C does call-by-value. Always.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at the above domain, - www.
     
    Richard Heathfield, Dec 17, 2006
    #2
    1. Advertising

  3. Chris Dollin Guest

    wrote:

    > Hi Everyone,
    >
    > I just came to know about a declartion, namely reference to a pointer
    > like the following,
    >
    > int *&p; //p is a reference to a pointer to an integer
    >
    > Is this valid only in C++ and not in C?


    It's not valid C: C doesn't support a C++-style reference type.

    > and i also came to know that there is a difference between call by
    > address and call by reference, can anyone tell me the exact difference?


    Suppose we have

    int cbr( int REFERENCE x ) { x += 1; }

    ... int b = 16; cbr( b ); assert (b == 17); [1] ...

    in some neuromatic C language with reference arguments. The
    variable `x` is a reference to whatever variable is given
    as actual argument: changing `x` changes the argument (and
    vice-versa). Hence incrementing `x` increments `b`.

    If we eliminate the REFERENCE magic, then assigning to `x`
    doesn't affect the actual argument variable, and the assert
    won't.

    The user of the term "call by address" that I have seen (and
    may have used ... beware circularity) looks like:

    int cba( int *x ) { *x += 1; }

    ... cbr( &b ); ...

    The address of the object is explicitly passed and the
    indirect manipulation of that object is signalled by the
    `*` operator.

    "Call by address" is what C (programmers) use(s) to compensate
    for C not having "call by reference".

    That's my story and I'm sticking to it.

    [1] A fake `assert` keyword. Pretend its the macro or
    a printf or whatever.

    --
    Chris "HO. HO. HO." Dollin
    "Who do you serve, and who do you trust?" /Crusade/
     
    Chris Dollin, Dec 18, 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. sam pal
    Replies:
    3
    Views:
    594
    E. Robert Tisdale
    Jul 16, 2003
  2. Replies:
    10
    Views:
    745
    Chris Torek
    Feb 4, 2005
  3. Replies:
    4
    Views:
    412
    Andre Kostur
    Dec 24, 2007
  4. mathieu
    Replies:
    8
    Views:
    532
    Juha Nieminen
    Aug 31, 2008
  5. A
    Replies:
    7
    Views:
    658
Loading...

Share This Page