It has been a while since I last programmed C, it seems I forgot everything at the same time ... I have a very simple question with a pointer. Assuming I have a function that calculates the sum through an iteration of a loop. This function should not only return the cycle counter, but also the amount that he calculated. Since I can simply return a single value, I assume I could have the sum declare a pointer. Can I do it like this:
int loop_function(int* sum) { int len = 10; for(j = 0; j < len; j++) { sum += j; } return(j); } .... int sum = 0; loop_function(&sum); printf("Sum is: %d", sum);
Or do I need to define an additional variable that indicates the amount that I then pass to the function?
Thanks a lot Marcus
source share