-
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)
-
cout<<"pn="<<*pn;//the * returns the value in the address
-
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;