Why do you use pointers in function( int* () )

Jun 23, 2014 at 5:53pm
In code below you can see that we use for example
 
int *something (int *pointer)

why is this really used for? I mean isnt: int something (int *pointer) okay?


Last edited on Jun 23, 2014 at 5:54pm
Jun 23, 2014 at 6:00pm
I think this might be helpful:
http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/

The int * something means the return will be an address in memory containing the int value.

Maybe not as useful for intergers, but if your function was returning a structure or object that would be very useful.

Jun 23, 2014 at 6:02pm
Ow I see.

Thank you very much, didn't really know what to search on google for it.
Thanks for your answer!
Jun 23, 2014 at 6:06pm
int* something (int* pointer)

This function returns a pointer to variable something.

int something (int* pointer)

This function returns a value to variable something.

typically people returns pointers to functions for better performance, however, for int types, that's no big deal 'cause the overhead cost is minor but when you're working with user-defined types or even string objects it's best to return a pointer or reference to avoid copying all the elements you're passing, get it?

Jun 23, 2014 at 6:22pm
I kinda undrestand. I am learning from book jumping into c++ but since I am not native english speaker It is harder to understand everything. Is it possible that you make 2 short examples? // how I understand;
1
2
3
4
5
int *returnPOINTER (int *pointer)
{
       int *pointer += 50;
       return pointer;
}

this is going to return pointer + its going to be faster?

the one with without pointer, int something (*pointer), will be slower + you re returning value?
Last edited on Jun 23, 2014 at 6:26pm
Jun 23, 2014 at 6:24pm
Don't read Jumping into C++, sure it's a good book for beginners but there are much more better books out there, here's a good one check it out: http://ebooks.z0ro.com/ebooks/C_and_C%2B%2B/C%2B%2B_Through_Game_Programming.pdf

Topic archived. No new replies allowed.