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

How do you write a function that can reverse a linked-list?

582


Which operator cannot overload?

551


What is atoi in c++?

576


There are 100 students in a class. The management keep information in two tables. Those two tables are given like Roll no Name Age 001 ABC 15 002 XYZ 14 and Roll No Subject Marks 001 Math 75 001 Physics 55 002 Math 68 001 Hindi 69 They want the information like this Roll No Name Hindi Physics Math Total 001 ABC 69 55 75 199 002 XYZ 68 74 84 226 And Roll No Suject Highest 001 Math 98 007 Physics 84 021 Hindi 74 All 275 All information is kept in structure in main memory. You have to find last two tables.

2545


Can you pass a vector to a function?

544






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

570


What are the advantages of using const reference arguments in a function?

624


What do you mean by friend class & friend function in c++?

627


What is the use of "new" operator?

667


What does extern mean in a function declaration in c++?

710


What is a stack? How it can be implemented?

702


What are the effects after calling the delete this operator ?

567


What is a down cast?

619


What are the advantages of using a pointer? Define the operators that can be used with a pointer.

613


Write a program to concatenate two strings.

595