NEWB Pointer problem

This is a discussion on NEWB Pointer problem within the C++ Programming forums, part of the General Programming Boards category; in main() : ----> int num = 1; function call : ---->ClassInstance.Write(&num,1); function prototype : int Cls::Write(int *pn, int food) ...

  1. #1
    Unregistered
    Guest

    NEWB Pointer problem

    in main() :
    ----> int num = 1;

    function call :
    ---->ClassInstance.Write(&num,1);

    function prototype :
    int Cls::Write(int *pn, int food)


    In the function how can i see what is in *pn ?

    When i say---> cout<<"pn = "<<(int)pn<<endl;
    ---result = 1244044, IT SHOULD BE 1


    i'll need to say stuff like if (total > pn)

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    cout<<"pn="<<*pn;//the * returns the value in the address

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    108
    You do not need to cast "pn" to an integer, it has already been declared a pointer to an integer type. Casting pointers to a particular type is used mostly with type void pointers.

    A pointer holds the RAM address of a particular type, it must be dereferenced to get the value stored at that RAM address...

    cout << "* pn = " << * pn;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointer to pointer realloc problem
    By prakash0104 in forum C Programming
    Replies: 14
    Last Post: 04-06-2009, 09:53 PM
  2. A problem with pointer initialization
    By zyklon in forum C Programming
    Replies: 5
    Last Post: 01-17-2009, 12:42 PM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. pointer problem
    By DMaxJ in forum C Programming
    Replies: 4
    Last Post: 06-11-2003, 01:14 PM

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