Computer Science & C Programming


Sub-programs definition & call

  1. A block of code can be reused by (a) defining a sub-program and (b) calling it.
    Thus
int main() {
   int x = -12;
   if (x<0) { x=-x; } else {}
   printf("%i",x);
   return 0;
}

is equivalent to

void abs() { // DEFINITION //
   int x = -12;
   if (x<0) { x=-x; } else {}
   printf("%i",x);
}

int main() {
   abs();   // CALL //
   return 0;
}

2 - 10