Thread: Basic pointer q

  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
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    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, 09:40 PM
  4. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 10:28 AM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM