Differentiate between declaration and definition in C++?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What data structure is fastest, on average, for retrieving data: a) Binary Tree b) Hash Table c) Stack

578


If a base class declares a function to be virtual, and a derived class does not use the term virtual when overriding that class, is it still virtual when inherited by a third-generation class?

603


Why c++ is better than c language?

555


What is lambda expression c++?

571


Is there a sort function in c++?

543






Why is c++ still best?

547


Describe linked list using C++ with an example.

641


How java is different from c and c++?

631


How should runtime errors be handled in c++?

607


What is polymorphism & list its types in c++?

612


What is the best it certification?

576


How can you quickly find the number of elements stored in a static array? Why is it difficult to store linked list in an array?

576


Why do we need function?

595


Comment on local and global scope of a variable.

573


What is polymorphism and its type in c++?

581