Differentiate between declaration and definition in C++?



Differentiate between declaration and definition in C++?..

Answer / atul shankhwar

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.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

What do you mean by abstraction. Explain your answer?

5 Answers  


Explain how to initialize a const member data.

0 Answers  


What is a .lib file in c++?

0 Answers  


In a function declaration what does extern means?

0 Answers   Flextronics,


What are the various compound assignment operators in c++?

0 Answers  


What is the difference between public, private, and protected access?

0 Answers  


Differentiate between realloc() and free().

0 Answers  


difference between macro and function?

3 Answers  


what do you mean by memory management operators

4 Answers   HCL,


What is difference between initialization and assignment?

12 Answers   HCL, HP, Infosys,


What is function prototyping?

0 Answers  


What are templates? where we should use it?

2 Answers   Alcatel,


Categories