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

Write a recursive program to calculate factorial in c++.

0 Answers  


What is lazy initialization in c++?

0 Answers  


If a round rectangle has straight edges and rounded corners, your roundrect class inherits both from rectangle and from circle, and they in turn both inherit from shape, how many shapes are created when you create a roundrect?

0 Answers  


Which c++ operator cannot overload?

0 Answers  


Write about the local class and mention its use?

0 Answers  






Can you sort a set c++?

0 Answers  


The "virtual" specifier in a member function enables which one of the following? a) Monmorphism b) Late binding c) Metamorphism d) Solomorphism e) Inheritance

4 Answers   Quark,


implement stack using stack.h headerfile functions

1 Answers   Exilant, GMG, Subex, University,


Why do we learn c++?

0 Answers  


Explain how would you handle a situation where you cannot call the destructor of a local explicitly?

0 Answers  


Explain the difference between static and dynamic binding of functions?

0 Answers  


What is lambda in c++?

0 Answers  


Categories