1. incr() is adding 1 to each variable in the array (well, the first 2 because i'm lazy). its my example of a method that modifies several variables stored in an array. Of course you cant store a variable in an array, you can only store values in there.
so, you have 3 choices;
1. copy the variable values into an array, pass the array for modification by the method, copy the new values back out of the array into your variables.
2. populate the array with the addresses of your variables (pointers) so the method can access them indirectly (what i did)
3. pass the variables directly, by reference. which is what you should really do.
2. yes, its personal taste, i always use int* x; because i'm thinking "int pointer" others use int *x; because they want to associate (in their mind) the "pointerness" with x;
consider...
int a,*b,c;
two ints and a pointer to an int. I can't do that with my style, but thats ok because i always declare each variable separately.
1 2 3
|
int a;
int* b;
int c;
|
it's just personal taste, or if you're a professional your employer may specify how it should be done in a "coding standard" document so all devs in a team do the same thing.