
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
What is the difference between a definition and a declaration in C++?
In C++, declaration and definition are often confused. A declaration means (in C) that you are telling the compiler about type, size and in case of function declaration, type and size of its parameters of any variable, or user-defined type or function in your program. No space is reserved in memory for any variable in case of the declaration.
The Definition on the other hand means that in additions to all the things that declaration does, space is additionally reserved in memory. You can say "DEFINITION = DECLARATION + SPACE RESERVATION".
Following are examples of declarations −
extern int a; // Declaring a variable a without defining it struct _tagExample { int a; int b; }; // Declaring a struct int myFunc (int a, int b); // Declaring a function
While following are examples of definition −
int a; int b = 0; int myFunc (int a, int b) { return a + b; } struct _tagExample example;
- Related Articles
- What is the difference between declaration and definition in C#?
- Explain the Difference Between Definition and Declaration
- Difference between Definition and Declaration in Java.
- Dying Declaration: Meaning and Definition
- What is the difference between a++ and ++a in JavaScript?
- Internal Table itab declaration in SAP and difference between both the declarations
- What is the difference between a simile and a metaphor?
- What is the difference between a method and a function?
- What is the difference between a storm and a cyclone?
- What is the difference between numeral and a number?
- What is the difference between a Telescope and Microscope?
- What is the difference between a fraction and integers ?
- What is the difference between the country and a continent?
- What is the difference between a python list and a tuple?
- What is the difference between a python tuple and a dictionary?

Advertisements