PDA

View Full Version : C++ Functions


Serex
07-07-2005, 07:11 AM
Hey all. I had taken a break from C++ for some time now. Have returned and am going to go from the bottom and try pick up all of the stuff i missed.

I currently am testing and playing around with functions / arrays.

i have a function that will create an array of data. Is it possible for me to 'load' the array into main() without returning anything. or will i have to return some sort of pointer to the array?

thanks

shmoove
07-07-2005, 08:11 AM
What do you mean by "'load' the array into main() "?
Are you looking for something like a global variable (for the array, and then it is accesible to all functions without passing any pointers around)?

shmoove

Serex
07-07-2005, 09:17 AM
sorry. by load i mean make them accessable from main(). i dont mind if i have to use pointers and it prefer to try avoid globals if possible

shmoove
07-07-2005, 10:29 AM
Then returning a pointer is the way to go. It's definitely more recommended than using globals (but then again, in some cases a global might just make life easier, so it depends on the context).

shmoove