Technically it is not required to separate declaration and definition, if and only if the code that calls this specific function comes later in the code than the definition/declaration. So this is valid: void a() {...} int main(...) {a() ;} while this is not: int main(...) {a() ;} void a() {...} The reason for this is that c compilers used a single pass to resolve all symbols Answer from Deleted User on reddit.com
🌐
Reddit
reddit.com › r/c_programming › i'm trying to understand the difference between function declaration and function definition in c programming.
r/C_Programming on Reddit: I'm trying to understand the difference between function declaration and function definition in C programming.
July 11, 2025 -

Here’s what I know, but I would appreciate clarification or examples:

  • A function declaration specifies the return type, function name, and parameters. It ends with a semicolon and tells the compiler about the function's signature but doesn’t contain the implementation. For example: int add(int num1, int num2);

  • A function definition actually implements the function with the code inside curly braces. For example: c int add(int a, int b) { return a + b; }

Some specific questions I have:

  1. Why is it sometimes okay to declare a function without parameter names but you must always specify parameter types?

  2. Can a function declaration and definition differ in the way parameters are named?

  3. What is the practical benefit of separating declaration and definition in bigger projects?

  4. Are there any common mistakes beginners make regarding declaration vs definition?

Thanks in advance for your help!

🌐
GeeksforGeeks
geeksforgeeks.org › computer science fundamentals › function-declaration-vs-function-definition
Function Declaration vs. Function Definition - GeeksforGeeks
Function Declaration introduces the name, return type, and parameters of a function to the compiler, while Function Definition provides the actual implementation or body of the function.
Published   January 16, 2026
Top answer
1 of 4
9
what is the difference between function definition and function declaration? A function definition is the actual function (it defines what the function does). To understand function declarations, assume that the compiler does a single pass over the source code (because computer hardware was extremely limited 50+ years ago when C was designed); but the code is like: int foo(int x) { bar(x); } int bar(int x) { return x+1; } .. so the compiler has no idea what "bar()" is when it's called from inside "foo()" because it hasn't reached that function yet, and throws an "Error: WTF is this thing?". A declaration fixes that problem by telling the compiler minimal details of a function earlier, before it's called (and before its defined), so that hopefully (if the declaration actually matches the definition) the compiler doesn't get all confused. Of course once you've got something for one purpose, it ends up getting used for other purposes too; like describing functions that are defined in other compilation units where the definition wouldn't be seen later anyway. also why do we enter parameters in a definition/declaration but not when we call a function? I'm going to assume you meant "parameter names" here. For function definitions, parameters need names for the same reason variables have names - so the compiler knows where the parameter is being used. For function declarations, parameters don't actually need names (e.g. "int foo(int);" is fine); but it's nice to have a clue what the parameters are for, and easier to just copy and paste the info from the function definition. For function calls, typing the parameter names (like maybe "foo(x = 5);") would have been tedious extra typing back when people were using plain text editors (rather than fancy IDEs with complex auto-completion stuff) and it's more fun if there's bugs everywhere because the parameters are in the wrong order (it's like hunting for Easter eggs!). Of course because function declarations don't need parameter names they're ignored; so it's perfectly fine to do something like: double calculateVolumeOfCylinder(int height, int radius); double calculateVolumeOfCylinder(int radius, int height) { return 3.141 * radius * radius * height; } ..and this can make your coworkers very happy with all the extra bug finding fun it creates.
2 of 4
3
I'm guessing you're talking about the C language. In a function declaration, we give the function's name, return type, parameter formal names and their type as well, but not the actual body of the function, so something like int add(int a, int b). We usually put that declaration in a .h file The function declaration is enough for the compiler to check that the function is only sent two ints, and its return value is used as an int. The compiler doesn't need to know what the function actually does in order to make this check. Note that I'm using "compiler" in the broadest sense of the word meaning: all the stuff that's needed to turn your source code into executable code. I'm not sure what you mean by not needing parameters when we call a function, since we do. In order to call the function above, you'd do something like add(2,3) where 2 and 3 are the parameters.
Top answer
1 of 4
19

Yes, they are different.

In the first example, you are just telling the compiler about the name and return type of the function and nothing of its expected arguments.

In the second example you are telling the compiler the full signature of the functions, both return type and expected arguments, prior to calling them.

The second form is pretty much universally better as it helps you compiler do a better job warning you when you have the wrong type or number of arguments when calling the function.

Also note int function() in C is a function that can accept any arguments, not a function that accepts no arguments. For that you need an explicit void, i.e int function(void). This mostly trips up those coming to C from C++.

See also: Why does a function with no parameters (compared to the actual function definition) compile?

To demonstrate why the first, antiquated form is bad in modern C, the following program compiles without warning with gcc -Wall -ansi -pedantic or gcc -Wall -std=c11.

Copy#include<stdio.h>
int foo();

int main(int argc, char**argv)
{
  printf("%d\n", foo(100));
  printf("%d\n", foo(100,"bar"));
  printf("%d\n", foo(100,'a', NULL));
  return 0;
}

int foo(int x, int y)
{
  return 10;
}

UPDATE: M&M brought to my attention that my example uses int not float for the functions. I think we can all agree that declaring int function1() is bad form, but my statement that this declaration accepts any arguments is not quite correct. See Vlad's answer for relevant spec section explaining why that is the case.

2 of 4
14

The difference is that then there is a function prototype as in the second code snippet then the compiler checks that the number and types of arguments correspond to the number and types of the parameters. The compiler can issue an error at the compilation-time if it will find an inconsistence.

If there is no function prototype as in the first code snippet then the compiler performs default argument promotions on each argument that includes the integer promotions and conversion of expressions of type float to type double. If after these operations the number and types of promoted arguments do not correspond to the number and types of parameters the behaviour is undefined. The compiler can be unable to issue an error because the function definition can be in some other compilation unit.

here are relevant quotes from the C Standard (6.5.2.2 Function calls)

2 If the expression that denotes the called function has a type that includes a prototype, the number of arguments shall agree with the number of parameters. Each argument shall have a type such that its value may be assigned to an object with the unqualified version of the type of its corresponding parameter.

6 If the expression that denotes the called function has a type that does not include a prototype, the integer promotions are performed on each argument, and arguments that have type float are promoted to double. These are called the default argument promotions. If the number of arguments does not equal the number of parameters, the behavior is undefined. If the function is defined with a type that includes a prototype, and either the prototype ends with an ellipsis (, ...) or the types of the arguments after promotion are not compatible with the types of the parameters, the behavior is undefined. If the function is defined with a type that does not include a prototype, and the types of the arguments after promotion are not compatible with those of the parameters after promotion, the behavior is undefined, except for the following cases:

— one promoted type is a signed integer type, the other promoted type is the corresponding unsigned integer type, and the value is representable in both types;

— both types are pointers to qualified or unqualified versions of a character type or void.

As for your code snippets then if the second parameter had type double then the code would be well-formed. However as the second parameter has type float but the corresponding argument will be promoted to type double then the first code snippet has undefined behaviour.

🌐
Weber State University
icarus.cs.weber.edu › ~dab › cs1410 › textbook › 6.Functions › def_and_dec.html
6.2.1. Function Definitions and Declarations
But unlike variable declarations, function declarations are essential, so they have a distinct name. Function declarations are typically called function prototypes or just prototypes for short. Before we study how to use prototypes, let's see what they look like and how they relate to function ...
🌐
GNU
gnu.org › software › c-intro-and-ref › manual › html_node › Function-Declarations.html
Function Declarations (GNU C Language Manual)
A function declaration looks like the start of a function definition. It begins with the return value type (void if none) and the function name, followed by argument declarations in parentheses (though these can sometimes be omitted).
Find elsewhere
🌐
W3Schools
w3schools.com › c › c_functions_decl.php
C Function Declaration and Definition
You will often see C programs that have function declaration above main(), and function definition below main(). This will make the code better organized and easier to read: // Function declaration void myFunction(); // The main method int main() { myFunction(); // call the function return 0; } // Function definition void myFunction() { printf("I just got executed!"); } Try it Yourself » ·
🌐
Pediaa
pediaa.com › home › technology › it › programming › what is the difference between function declaration and function definition in c programming
What is the Difference Between Function Declaration and Function Definition in C Programming - Pediaa.Com
February 28, 2019 - The main difference between Function Declaration and Function Definition in C Programming is that the function declaration indicates what the function is and function definition indicates what the function does.
🌐
Log2Base2
log2base2.com › C › function › function-definition-in-c.html
Function Definition | Function Declaration vs Function Definition
Free AI-powered learning on Leyaa.ai ... statements. Write a function to add two numbers and return their sum. ... In the function declaration, we are giving information about the function to the compiler....
🌐
Quora
quora.com › Can-you-explain-the-difference-between-function-call-function-definition-and-function-declaration
Can you explain the difference between function call, function definition, and function declaration? - Quora
Good question! A function definition is the actual code that is executed within the function. The function declaration, is the name and parameters of the function including return type.
🌐
Quora
quora.com › What-is-a-declaration-and-definition-of-a-function-in-C-programming-language
What is a declaration and definition of a function in C programming language? - Quora
Answer (1 of 2): void foo (); // this is the declaration, usually in a header. void foo () { // function body } // this is the definition / implementation of the function declared in the header This is usually done in a .c file
🌐
GeeksforGeeks
geeksforgeeks.org › c language › c-functions
Functions in C - GeeksforGeeks
A declaration tells the compiler about the function's name, return type, and parameters before it is actually used. It does not contain the function's body. This is often placed at the top of the program or in a header file.
Published   January 24, 2026
Top answer
1 of 16
1078

A declaration introduces an identifier and describes its type, be it a type, object, or function. A declaration is what the compiler needs to accept references to that identifier. These are declarations:

extern int bar;
extern int g(int, int);
double f(int, double); // extern can be omitted for function declarations
class foo; // no extern allowed for type declarations

A definition actually instantiates/implements this identifier. It's what the linker needs in order to link references to those entities. These are definitions corresponding to the above declarations:

int bar;
int g(int lhs, int rhs) {return lhs*rhs;}
double f(int i, double d) {return i+d;}
class foo {};

A definition can be used in the place of a declaration.

An identifier can be declared as often as you want. Thus, the following is legal in C and C++:

double f(int, double);
double f(int, double);
extern double f(int, double); // the same as the two above
extern double f(int, double);

However, it must be defined exactly once. If you forget to define something that's been declared and referenced somewhere, then the linker doesn't know what to link references to and complains about a missing symbols. If you define something more than once, then the linker doesn't know which of the definitions to link references to and complains about duplicated symbols.


Since the debate what is a class declaration vs. a class definition in C++ keeps coming up (in answers and comments to other questions) , I'll paste a quote from the C++ standard here.
At 3.1/2, C++03 says:

A declaration is a definition unless it [...] is a class name declaration [...].

3.1/3 then gives a few examples. Amongst them:

[Example: [...]
struct S { int a; int b; }; // defines S, S::a, and S::b [...]
struct S; // declares S
—end example

To sum it up: The C++ standard considers struct x; to be a declaration and struct x {}; a definition. (In other words, "forward declaration" a misnomer, since there are no other forms of class declarations in C++.)

Thanks to litb (Johannes Schaub) who dug out the actual chapter and verse in one of his answers.

2 of 16
191

From the C++ standard section 3.1:

A declaration introduces names into a translation unit or redeclares names introduced by previous declarations. A declaration specifies the interpretation and attributes of these names.

The next paragraph states (emphasis mine) that a declaration is a definition unless...

... it declares a function without specifying the function’s body:

void sqrt(double);  // declares sqrt

... it declares a static member within a class definition:

struct X
{
    int a;         // defines a
    static int b;  // declares b
};

... it declares a class name:

class Y;

... it contains the extern keyword without an initializer or function body:

extern const int i = 0;  // defines i
extern int j;  // declares j
extern "C"
{
    void foo();  // declares foo
}

... or is a typedef or using statement.

typedef long LONG_32;  // declares LONG_32
using namespace std;   // declares std

Now for the big reason why it's important to understand the difference between a declaration and definition: the One Definition Rule. From section 3.2.1 of the C++ standard:

No translation unit shall contain more than one definition of any variable, function, class type, enumeration type, or template.

🌐
Aleksandar Haber
aleksandarhaber.com › what-is-the-difference-between-function-declaration-and-definition-in-c-or-c
What is the difference between function declaration and definition in C or C++? – Fusion of Engineering, Control, Coding, Machine Learning, and Science
Name of the function. The declaration of the function specifies the name of the function that the compiler needs to know. The number of input arguments (parameters) that the function accepts, and the data types of the input arguments (parameters).
🌐
Cprogramming.com
cprogramming.com › declare_vs_define.html
What's the difference between declaring and defining in C and C++ - Cprogramming.com
How to begin Get the book · C tutorial C++ tutorial Game programming Graphics programming Algorithms More tutorials
🌐
Quora
quora.com › What-is-the-difference-between-function-definition-and-function-declaration-in-the-C-C-programming-language
What is the difference between 'function definition' and 'function declaration' in the C/C++ programming language? - Quora
Answer (1 of 4): 01) =========== Assume that there is a main program MainPg.cpp =========== #include "setc_err.hxx" // include this file to include the prototype of function displaySetcCancelTicketRefund #include using namespace std; // Re-declartion of displaySetcCancelTicketRefu...