Declaration, Definition, Call of Function |Functions in C Programming | Introduction to Functions


in this one we will see how to use a functions in a c programming the function is a basically collection of the statements which is used to do a particular tasks now in c programming each and every program contains at least one function so which is called as a main function so here we have given a return type name to the function and within the curly brackets we have given a body to the function now a user defined a function how a similar view and have a similar behave like this 

so here first of all we will see the syntax of the user defined

return-type function-name(parameters)

a function so here we have to use a return type again we have to use the function name and inside the brackets we have to use the parameters so here the function can take any parameters and here if we do not want to give any parameters we can keep these parentheses blank like this

int main ()

 and after that we have to use some curly brackets to define the

body for the function now  we will see how to use a function to display some message on the screen so let's see how to do this





 so first of all we need to use a return type so here I am using the return type void now here if you do not want to return any value from the function then we can use avoid data type then again we have to use a function name so q function name hello and give two packets and here inserting two brackets we can pass a parameters but for now I do not want to pass any parameters so I am just keeping this blank and inside the curly brackets we have to write a body for our hello function so here my work is to display a message on the screen so I will produce print f 

hello world just want to print this on my output screen now here we have declared and defined a one function now our second thing is to call these function from the main function so here to call the function we have to use just function name like hello and give two brackets and just to give a semi-coma so here remember that execution is alibis start from the main function so here execution will start and if whenever the hello will get encounter that means whenever a function call delegate encountered the control will get passed to this body of the function so here whatever we have written a body for for the function it will get executed and after that the control will again get pass through the main function and the remaining body of the main function will get executed. the execution start from the main function and here it encounters through this flake that means here it encounters the function call so the control gate pass through this definition of the function and here the body of the function get executed so inside that we have written the printf function that means the message get printed on the screen and after completion of this function execution the control again get passed with the main function and the main core of the main get execute now suppose if you want to use this function for more paths then we can just simply use this four more times like this so here we have used to the hello function for three times so these message will get printed for the three times .

printed for the three times now here we have declared and defined our function and the above to the main function now suppose if you if you want to declare and define the function at the below to the main function then we can simply just use a similar procedure

like this 



so here we have again given a return type given a function name and we have defined at the body now the additional thing that we have to do is to prototype this function because here we are just declaring and defining our function at the below to the main

function so here we have to do some prototyping so to do prototyping just copy this function name with the return type and these two brackets so copy these and put these I could be about to the main function like this and give the same a comma so this is called as a prototyping so we need this because we have to tell the compiler that I am going to use this function hello in my program so we have to tell this to compiler like this so this is called as a prototyping 

output is this is a function and the message got printed for the three times because here we have called the function for the three times now in this way in c programming we can use these functions and the function is used to do some particular task again and again 

Post a Comment

0 Comments