Difference in C ++ declarations and definitions

1, the definition includes the statement, but the statement does not contain a definition,

Such as

int a = 0 ; // declare variables and defines a extern int a ; // only declares a variable a is present, where to find a particular definition, require the compiler to compile time.     

2, the function is similar to the definition of the time when the statement. However, if only a statement, the compiler only knows there is such a function, a function of how specific definition to the compiler to find.

void fun1 (); // declare function void fun1 () { // function definition COUT << "fun1" << endl ; }     

3, C / C ++ compiler cpp file is compiled from the top down, so when the main function of which call other functions, if other functions in the following main function, they have to first declare the function in the main function above.

Or the main function on the bottom, this is not limited to the main function calls other functions alike. Function is called to declare before the function call

 

Guess you like

Origin www.cnblogs.com/gkh-whu/p/11457211.html