Hey Everyone, I am Vikram Salunke and welcome to x86 Assembly course.

Now let's look at the Functions.

- Function is a group of statements that together perform a task.

- Every C program has at least one function main().

- Function declaration tells the compiler about function's name, it's return type and it's parameters.

- Function definition provides actual body of function.

Let's see function in a program.

c programming basics functions

This is my C program.
First we are including stdio.h file to include all the functions from stdio.h header file.

In the main, we are defining 3 variables num1, num2 and total.

After that we are printing on a screen i.e. Enter the num1 then user will enter number1 and it will be stored in a num1.

After that we are printing on a screen Enter number 2 and we are saving the value entered by the user into the num2.

After that we are using total = add(num1, num2).

So, the total is 3rd variable which is saving the total of a number1 and number2.

Let's look at the add

In the upper section we can see a function int add(int num1, int num2)

We are defining a add function.

It's data type is int and it has a 2 parameters int num1, int num2.

main() is passing the num1 and num2 to the add function.

So, we have to define 2 parameters of int type

{ indicate that add's body started

This function is adding num1 and num2 and returning.

So, where it's returning? it's returning to the total.

The total variable will now get addition of number1 and number2 and what we are doing? we are printing the total onto the screen.

And we are exiting the program by placing the return value 0.

Let's run the program

c programming basics functions

We have entered num1 as 10 and num2 as 20. And we got the Total of that.

So that's it for this post.

If you want to join our in person class then please click here we are doing trainings in some upcoming InfoSec conferences.
And if you have any doubts, any questions then you can tweet me @vikramsalunke20
We are uploading daily new videos on YouTube click here to subscribe.
If you want to solve the exercises on this topic those are below. Solve the exercises and check your understandings. Thank you :)