You aren't making n point to anything, so you are assigning 5 to a random memory location.
n is the memory location, *n is the value stored in the memory location.. at least that is how I come to understand it.
I got by it by making numberTemp, a standard variable.
I needed numberTemp to be accessible by reference, so I just passed it by reference using &, rather than using a * for pointing.
when you declaring pointer like
the pointer, like any other builtin type, remains uninitialized. To initialize it, you can do:
1 2
|
double var;
double * pvar=&var;//pvar now stores address of stack variable
|
or you can create new variable in the heap:
|
double * pvar=new double;//pvar now stores address of newly created heap variable
|
but you must delete such variable after use.
Last edited on
hi vukki, that looks to be quite educational, thanks for your response. will have to try it out!