Thread: Basic pointer q

  1. #1
    Registered User
    Join Date
    May 2009

    Basic pointer q

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

    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
    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
Website Security Test