View Single Post

Member Since: Dec 09, 2008
Posts: 19
systix is on a distinguished road

systix is offline
I don't know objective-c, i aim to learn though. In C however a good example of the use of pointers is a function that swaps two values. eg

voide main()
    int val1, val2;
    swap (val1, val2);

int swap (int val1, int val2)
     int temp = val1;
     val2 = val1;
     val1 = temp;

This will not work. The values are copied into the swap() function and swapped within the scope of the function, but not externaly to it. However, if we pass in pointers to the original variables we can indirectly access them and the swap will occure on the original values.

I hope this helps!
QUOTE Thanks