User-defined functions in C consist of several elements:
Function Declaration: The function declaration provides the compiler with information about the function's name, return type, and parameters (if any).
Example: int addNumbers(int a, int b);
Function Definition: The function definition contains the actual implementation of the function, specifying what it does.
Example:
int addNumbers(int a, int b) {
return a + b;
}
Return Type: The return type specifies the type of data that the function will return.
Example: int in int addNumbers(int a, int b);
Function Name: The function name is an identifier used to call the function.
Example: addNumbers in int addNumbers(int a, int b);
Parameters: Parameters are variables that the function accepts as input. They are declared within the parentheses.
Example: (int a, int b) in int addNumbers(int a, int b);
Function Body: The function body contains the statements that define the logic of the function.
Example:
int addNumbers(int a, int b) {
return a + b;
}
Return Statement: The return statement specifies the value that the function sends back to the calling code.
Example: return a + b; in the addNumbers function.
Here's an example combining these elements:
Program.c
Output:
Sum: 12
Resources :
Featured
Special title treatment
With supporting text below as a natural lead-in to additional content.