Basic pointer q

This is a discussion on Basic pointer q within the C Programming forums, part of the General Programming Boards category; Hmm...Can I replace *area= A * B with area = &(A * B)? Code: void rectangleMath(double *area, double *perim, double ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    29

    Basic pointer q

    Hmm...Can I replace *area= A * B with area = &(A * B)?


    Code:
    void rectangleMath(double *area, double *perim, double A, double B)
    {
    *area = A * B;
    *perim = (A + B) * 2;
    }

  2. #2
    cas
    cas is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    975
    No. & takes the address of something. A*B has no address.

    If you could, it wouldn't be the same thing. *area = A*B changes the object that area points to. area = &(A*B), if it were legal, would set the value of the local pointer called area to the address of A*B. The first way modifies the object in the caller (which is, presumably, the desired behavior here). The second way would modify the pointer only, and the object in the caller would not change in value.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why does C need pointer conversion
    By password636 in forum C Programming
    Replies: 2
    Last Post: 04-10-2009, 07:33 AM
  2. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  3. scope of a pointer?
    By Syneris in forum C++ Programming
    Replies: 6
    Last Post: 12-29-2005, 08:40 PM
  4. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 09:28 AM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21