I'm struggling to get to grips with pointers - namely passing them between functions.
For example, I can get a pointer INTO a function
eg.
int main(void)
{
..
pPointer = (int*)malloc(80);
..
UsePointer(pPointer);
..
}
int UsePointer(int* pPointer)
{
// I can have access to pPointer
// as I did in main
..
}
But what if I wanted to set up this pointer within a separate function, and pass it back to main -
eg.
int main(void)
{
..
pPointer = GetPointer();
..
}
How do I label the function GetPointer()?
int* GetPointer() <= ???
{
// Set up pPointer
..
return (pPointer);
}
I hope I've made myself clear. I just can't find out for the life of me how to do this!
Any help would be much appreciated.
Cheers,
Dan Roberts.
For example, I can get a pointer INTO a function
eg.
int main(void)
{
..
pPointer = (int*)malloc(80);
..
UsePointer(pPointer);
..
}
int UsePointer(int* pPointer)
{
// I can have access to pPointer
// as I did in main
..
}
But what if I wanted to set up this pointer within a separate function, and pass it back to main -
eg.
int main(void)
{
..
pPointer = GetPointer();
..
}
How do I label the function GetPointer()?
int* GetPointer() <= ???
{
// Set up pPointer
..
return (pPointer);
}
I hope I've made myself clear. I just can't find out for the life of me how to do this!
Any help would be much appreciated.
Cheers,
Dan Roberts.