Function is a collection of statements. It means function is a block of code. Each and every c program used at least one function. Function is used to perform special type work.
C language provides more inbuilt functions. All inbuilt functions are defined by c language. Inbuilt function is called "predefine function". It is also called "library function".
That function definition is defined by user(programmer) that is called "User define function". In this tutorial we are learning "User define function".
NOTE:- you can learn predefine function or library function in different-different chapters.
There are three types of function in c language.
(1) default function
(2) parameterize function
(3) return type function
It is also called non-parameterize function.
return-type: It tells what type value can be return from function. return type is same as data-type like void, int, float, etc.
functionName: It is the name of function. It is given by user(programmer).
Syntax
return-type functionName( ){
/* Type here block of code. */
}
Syntax
functionName();
Below program calculate odd or even number using function.
Syntax
return-type functionName( data-type variableName1, data-type variableName2,.......... ){
/* Type here block of code. */
}
Where you have called your function all parameters receive value from there respectively. You can understand from above syntaxes. variableName1 will receive data from value1 and variableName2 will receive data from value2.
Syntax
functionName(value1, vlaue2,........);
Below program checks that a number is divided by 5 or not.
From below program you can understand "Optional Parameter" and "Required parameters". That parameter do not work without getting data(value) from user that is called "required parameter". It means user do not give value on parameter then compiler returns
NOTE: In above program a and b is required parameter but c and d is optional parameter.
"return" is a keyword. It is used to return value from function. "return" statement can be use with default function or parameterize function. A function returns only one value in one time calling. Mostly programmers use "return" as last statement.
If you have used "void" return-type then your function do not use "return" statement because void return-type do not return any value. Void is called empty return-type or data-type. It means you have used return-type excluding "void" then you can use "ret
Comsysapp.com is an educational website. Students and software developers can learn programming language tutorials. Comsysapp is very useful for beginners and professional developers. Comsysapp provides tutorial in easy language. Comsysapp.com has focus on simplicity.
Comsysapp.com provides free tutorials like c, html, css, etc. All tutorials are free for beginner and professionals.
comsysapp.com is not responsible for any mistake. We are not responsible if information made available on our website is incomplete or invalid. But comsysapp.com always try for zero-zero mistake.
comsysapp.com does not collect any data from users. We use Google AdSense advertising on our website. We never ask personal or private information.
copyright © 2023