Home > DeveloperSection > Interviews > What is the difference between declaration and definition?

Posted on    January-15-2015 10:16 PM

 1 Answer(s)
  531  View(s)
Rate this:

Ankit Singh

Total Post:15

Posted on    January-15-2015 11:16 PM

Difference between declaration and definition

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.

A definition actually instantiates/implements this identifier. It's what the linker needs in order to link references to those entities. 

The declaration tells the compiler that at some later point we plan to present the definition of this declaration.

E.g.: void stars () //function declaration
The definition contains the actual implementation.
E.g.: void stars () // declarator
for(int j=10; j > =0; j--) //function body
cout << *;
cout << endl; }

Modified On Mar-28-2016 04:12:15 AM

Don't want to miss updates? Please click the below button!

Follow MindStick