Added some info (#20123)
Some information has been added on how to define a function after the main program.pull/20891/head^2
parent
aa5e550c3b
commit
6e42246d53
|
@ -115,6 +115,31 @@ Recursion makes program more elegant and clean. All algorithms can be defined re
|
|||
If the speed of the program is important then you may not want to use recursion as it uses more memory and can slow the program down.
|
||||
|
||||
|
||||
## Defining a function after main program
|
||||
There can be instances when you provide the function definition after the main program. In those cases the function should be declared before the main program with arguments and should be ended with semi-colon(;). Later the function can be defined after the main program.
|
||||
|
||||
```C
|
||||
#include <stdio.h>
|
||||
|
||||
int divides(int a, int b);
|
||||
|
||||
int main(void) {
|
||||
int first = 5;
|
||||
int second = 10; //MUST NOT BE ZERO;
|
||||
|
||||
int result = divides(first, second);
|
||||
|
||||
printf("first divided by second is %i\n", result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int divides(int a, int b) {
|
||||
return a / b;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
# Before you go on...
|
||||
## A review
|
||||
* Functions are good to use because they make your code cleaner and easier to debug.
|
||||
|
|
Loading…
Reference in New Issue