🌟 Join our Telegram group for exclusive updates! Join Now Get Involved

Functions Declaration

Functions Declaration

Functions Declaration

A function consists of two parts:

  • Declaration: where we specify the function's name, its return type, and required parameters (if any).
  • Definition: which is nothing but the body of the function (code to be executed).

The basic structure of a function is:

return_type functionName() {
  // declaration
  // body of the function (definition)
}

For code optimization and readability, it is often recommended to separate the declaration and the definition of the function. This is the reason why you will often see C programs that have function declarations above the main() function, and function definitions below the main() function. This will make the code better organized and easier to read.

This is how it is done:

#include <stdio.h>

// Function declaration
void func();

int main()
{
    func(); // calling the function
    return 0;
}

// Function definition
void func()
{
    printf("This is the definition part.");
}

Output:

This is the definition part.

Cookies Consent

This website uses cookies to ensure you get the best experience on our website.

Cookies Policy

We employ the use of cookies. By accessing BYTEFOXD9, you agreed to use cookies in agreement with the BYTEFOXD9's Privacy Policy.

Most interactive websites use cookies to let us retrieve the user’s details for each visit. Cookies are used by our website to enable the functionality of certain areas to make it easier for people visiting our website. Some of our affiliate/advertising partners may also use cookies.