Logo 
Search:

C++ Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C++ ProgrammingRSS Feeds

Differentiate between declaration and definition in C++.

  Shared By: Adah Miller    Date: Jan 25    Category: C++ Programming    Views: 198

Answer:

A declaration introduces a name into the program; a definition provides a unique description of an entity (e.g. type, instance, and function). Declarations can be repeated in a given scope, it introduces a name in a given scope. There must be exactly one definition of every object, function or class used in a C++ program.

A declaration is a definition unless:
-> it declares a function without specifying its body,
-> it contains an extern specifier and no initializer or function body,
-> it is the declaration of a static class data member without a class definition,
-> it is a class name definition,
-> it is a typedef declaration.

A definition is a declaration unless:
-> it defines a static class data member,
-> it defines a non-inline member function.

Share: 
 
 
 
 

Didn't find what you were looking for? Find more on Differentiate between declaration and definition in C++. Or get search suggestion and latest updates.


Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: