• admin@embedclogic.com

User-defined Function in C

User-defined function as the name appears –“A function defined by a user/programmer”. these functions are not standard and these are the project-specific functions written by a programmer to make program modular and less complex.

Component of User-defined Function

There are three component in user-defined function –

— Function prototype declaration

— Function calling

— Function definition

use of three component in a program
Function prototype declaration

A function must be declared prior to its calling.The function declaration is an information for the compiler about the existence of a function in a program.

Syntax

return_type function_name(input1_dataType,input2_dataType);

return_type = function output data type e.g int ,char,float,double etc.

input1_dataType , input2_dataType = Function’s arguments data type int ,char,float,double etc.

Function Calling

A function can be called from anywhere in the program with proper arguments as declared in the prototype.

Syntax

function_name(input1,input2);

Note: Type of data must be same as declared in the prototype of function for correct output.

Function definition

A function definition has the set of statements under its name to perform any specific task.

Syntax

return_type function_name(dataType Input1,dataType Input2)

{

statement1;

statement2;

}

Example

Write a function to perform addition of two integers.

Subscribe and stay updated with our latest articles.

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

Embedclogic will use the information you provide on this form to be in touch with you and to provide updates and marketing.