C passes values not arguments — that is what I am told, but how do I fix this? I just don't understand.
#include <stdio.h> /* This will not work */ void go_south_east(int lat, int lon) { lat = lat - 1; lon = lon + 1; } int main() { int latitude = 32; int longitude = -64; go_south_east(latitude, longitude); printf("Now at: [%i, %i]\n", latitude, longitude); printf("The log pointer is at %x\n", longitude); } It doesn't update the values in main() — they stay at 32, -64 but should be 31, -63.
latitudeandlongitudeto your function, and rewrite the function to take pointers, and to modify the values that the pointers point at. And if you're not sure how to do that, please consult your text book. Note that if you printedlatandlonin thego_south_east()function, you'd see that they changed value, but the variables are local to the function, and changes to them do not affect the values in the calling function (main()).