Function in C: Function with Inputs and an Output

Function in C: Let’s assume we are going to write a function which takes inputs, and  returns an output. To be specific, we will provide 2 integers (input) to our function and our function will return the greater number (output). Just take a look at this code:

Here we have passed a and b when we call our function at line 14, and these parameters are received at line 3 as int num1 and int num2 (take a look at this and this post if you forget).

Lines 5 to 9 find a greater number between these two, assign the greater number to the answer, and finally return the answer (as the answer is an integer, our function definition has int at line 3) which is received by the greater_number at line 14.

Just one thing to keep in mind: when a Function in C encounters a return statement, it returns to the calling line immediately. Which means if any other statement is written after the return statement, the compiler will not care!

Take a look at this keyboard: Keychron V1 Max. I find it great in using for my programming tasks, office work, and even writing blogs. You can give it a try.

I hope it’s clear to you. Thanks!