C Programming

⌘K
  1. Home
  2. Docs
  3. C Programming
  4. Functions
  5. Defining a Function

Defining a Function

A function definition contains the actual body of the function — the block of code that performs the task.

Syntax:

return_type function_name(parameter_list) {
    // function body
}

Example:

int add(int a, int b) {
    return a + b;
}
  • This defines what the function add actually does — it returns the sum of two integers.

A function prototype is a declaration of a function that tells the compiler about the function’s name, return type, and parameters before its actual definition appears in the program.

Syntax:

return_type function_name(parameter_list);

Example:

int add(int a, int b);  // Function prototype
  • This tells the compiler that there is a function named add which takes two integers as arguments and returns an integer.

A function call is the statement that actually invokes the function. When a function is called, the program execution control transfers to the function’s body.

    Syntax:

    function_name(arguments);

    Example:

    int result = add(5, 3);  // Function call
    • This calls the add function with 5 and 3 as arguments, and stores the returned value in result.

    How can we help?

    Leave a Reply

    Your email address will not be published. Required fields are marked *