WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

C · Intermediate · question 37 of 100

What is the difference between a function declaration and a function definition in C?

📕 Buy this interview preparation book: 100 C questions & answers — PDF + EPUB for $5

In C programming, a function declaration and a function definition are two distinct concepts.

A function declaration is a statement that tells the compiler about the function name, its return type, and the types of its parameters. The purpose of a function declaration is to inform the compiler about the existence of a function so that it can be used in other parts of the program before it is defined. Function declarations are typically placed at the beginning of a C program or in a header file.

Here is an example of a function declaration:

    int add(int x, int y);   // function declaration

A function definition, on the other hand, is a statement that provides the implementation of the function. It contains the actual code that defines the behavior of the function. Function definitions are typically placed after the main function or other functions that they call.

Here is an example of a function definition:

    int add(int x, int y)    // function definition
    {
        return x + y;
    }

It is important to note that a function can be declared multiple times in a program, but it can only be defined once. The function definition is what actually creates the function and provides its behavior. If a function is used in a program but not defined, the compiler will generate an error.

In summary, a function declaration is a statement that tells the compiler about the function name, return type, and parameter types, while a function definition provides the implementation of the function. Function declarations are typically used to inform the compiler about the existence of a function so that it can be used before it is defined, while function definitions provide the actual code for the function’s behavior.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic C interview — then scores it.
📞 Practice C — free 15 min
📕 Buy this interview preparation book: 100 C questions & answers — PDF + EPUB for $5

All 100 C questions · All topics