Computer Science & C Programming


Sub-programs definition & call

  1. As a final improvement, the variable x can be transformed into a parameter
int abs(int x) {
   if (x<0) { x=-x; } else {}
   return x;
}

int main() {
   printf("%i", abs(-12) );
   printf("%i", abs( 24) );
}

Comments:
a. The parameters and returned value have a specific representation.
b. The printf is a sub-program having two parameter with a format, eg. "%i" for an integer, and a value.


4 - 10