When a parameter passed to a function uses a reference, when the parameter value is modified within the function, the corresponding parameter outside the function is modified.
void square( int *powers) { *powers=*powers * *powers; } int main() { printf("Hello lautturi!\n\n"); int i; int array[] = {1, 2, 3, 4, 5}; for (i=0; i<5; i++) { square(&array[i]); // Passing the address of array to the function } for (i=0; i<5; i++) { printf("%d ",array[i]); } return 0; }
output
Hello lautturi! 1 4 9 16 25