Functions in C Programming:
Definition
A function is a block of code that performs a specific task. Functions help
break our program into smaller and modular chunks for better organization
and code reusability. In C, a function can be defined as:
return_type function_name(parameters)
{
// function body
}
Parameters
Functions can accept zero or multiple inputs called parameters. These
parameters are defined within the parentheses, separated by commas. The
parameters act as local variables to the function and can be used within
the function body for computations or decisions.
Return Type
The return_type signifies the data type of the value the function will return
after executing. A function doesn't necessarily need to return a value; in
such cases, the return_type can be set to void.
Here are examples of function definitions with different return types and
parameters:
int add(int a, int b) // add two integers and return sum
{
return a + b;
}
void printHello() // no input, no output, just print "Hello"
Definition
A function is a block of code that performs a specific task. Functions help
break our program into smaller and modular chunks for better organization
and code reusability. In C, a function can be defined as:
return_type function_name(parameters)
{
// function body
}
Parameters
Functions can accept zero or multiple inputs called parameters. These
parameters are defined within the parentheses, separated by commas. The
parameters act as local variables to the function and can be used within
the function body for computations or decisions.
Return Type
The return_type signifies the data type of the value the function will return
after executing. A function doesn't necessarily need to return a value; in
such cases, the return_type can be set to void.
Here are examples of function definitions with different return types and
parameters:
int add(int a, int b) // add two integers and return sum
{
return a + b;
}
void printHello() // no input, no output, just print "Hello"