From 6e42246d531e4cfa666d1c3650f17802db93f247 Mon Sep 17 00:00:00 2001 From: allenpbiju <33065555+allenpbiju@users.noreply.github.com> Date: Sun, 4 Nov 2018 06:44:27 +0530 Subject: [PATCH] Added some info (#20123) Some information has been added on how to define a function after the main program. --- guide/english/c/functions/index.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/guide/english/c/functions/index.md b/guide/english/c/functions/index.md index 0cd067e930..adef507dfc 100644 --- a/guide/english/c/functions/index.md +++ b/guide/english/c/functions/index.md @@ -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 + +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.