Section 9.8: Changeable parameters implemented by pointers (Frame 1)                     [     ][home][next]

In some languages such as Pascal, Ada and C++, you can specify that some parameters can be changed inside the subroutine and those changes will "stick" when control returns to the caller. Others, like C and Java, do not permit parameters to be changeable. For example, the following program is legal C but does not do what you expect:

void increment (int x) {                      // This is legal C
     x = x + 1;   // similar to the x++ operation
}
int main() {
     int z = 5;
     increment(z);
     printf ("%d", z);   //   shows 5, not 6
}