Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a function to return a pointer

Status
Not open for further replies.

Beard36

Programmer
Sep 4, 2003
69
GB
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.
 
Ok. It turns out I was making a stupid mistake in my code. And that this question kinda answers itself.

Best just ignore it. :)
Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top