Syntax of a Function

General Syntax:-

return_type function_name(parameter_list) {

    // body of function

    return value; // if return_type is not void

}

 

Example:

int add(int a, int b) {

    return a + b;

}

Function Call:

int result = add(5, 3);

 

Function Declaration vs Definition vs Call

  • Declaration: Declares a function signature to the compiler before main.

int add(int, int); // Function Declaration

  • Definition: Contains the full logic of the function.

int add(int a, int b) {

    return a + b;

}

  • Call: Invoking the function from the main or another function.

add(4, 6);

 

Parameters and Arguments

  • Actual Parameters: Values passed during function call.
  • Formal Parameters: Variables defined in the function declaration/definition.