Functions are basically the block of codes which we have to use multiple times in the program like loops. Functions can reduce the number of lines of codes. Functions are executed when they are called from the main function. Functions are of two types :- </a> In-built Functions In-built Functions are printf, scanf, the ones which are predefined in the header file. </b> User-defined Functions User-defined Functions are the functions which the users create to reduce the number of lines of codes. How to Call a function? Before working in the main function, you need to tell the compiler that we have a Sub-function i.e User-defined function is there below the main function. To call the function, you need to follow the following syntax. functionName(dataTypeOfVariable1 nameOfVariable, dataTypeOfVariable2 nameOfVariable, ...); // This should be before the initialization of main function. How to declare a function? returnDataType functionName(dataTypeOfVariable1 nameOfVariable, dataTypeOfVariable2 nameOfVariable, ...) { ...... // block of codes ...... return(variable); } There are 4 types of User-defined Functions :- </a> Function with No Arguments and no Return Value In this type of User-defined Function, there is no argument and no return value. We simply need to call the Function from main. Then what about printing the value? It is done in the User-defined Function. Click Here for the Example Of Function with No Arguments and no Return Value. </b> Function with No Arguments and a Return Value Here, in this User-defined Function, still we aren't passing any argument, but return a value from the User-defined Function to the main function. Click Here for the Example Of Function with No Arguments and a Return Value. </c> Function with Arguments and no Return Value With Arguments and no Return Value means the User-defined Function is passed with the Argument and in it, it has the printing statements. Click Here for the Example Of Function with Arguments and no Return Value. </d> Function with Arguments and a Return Value In this, we have both the Argument along with the Return Value. Click Here for the Example Of Function with Arguments and a Return Value. Just to Remind You : dataType functionName(argument, arguments, ...)
Next
« Prev Post
« Prev Post
Previous
Next Post »
Next Post »
Subscribe to:
Post Comments (Atom)
0 Comment