Software & Finance





C++ FAQ - Difference Between Declaration and Definition





The declaration can be any number of numbers, but definition should be only one time.
The declaration does not allocate any memory in the stack, but definition allocates memory.

Example for a Variable

int m; // it is called both declaration and definition

 

extern int m; // it is just declaration and does not allocate any memory on the stack



Example for a Function

The declaration would end with the semi colon as shown below:


void TestFunc(int arg1, float arg2);


The definition will have open and end braces "{ }";

void TestFunc(int arg1, float arg2)

{

  arg1 = arg1;

  arg2 = arg2;

}