Home   |   About   |   Terms   |   Contact    
Read & Learn
 

What is Variable Declaration & Variable Definition in C++

C++

☯ All C++ Articles     ☯ All Articles


A new product.






Popular Google Pages:




This article is regarding Variable Declaration & Variable Definition in C++.
Last updated on: .



What is Variable Declaration & Variable Definition in C++ ?

Let a simple program:
#include <iostream>
using namespace std;
int world = 6;
int sky = 3;
int water;
int main()
{
water = world + sky;
cout << "The total is:" << water << endl;
return 0;
}



◕ Variable Declaration:
A variable declaration is a statement that declare the name & type of a variable.
Example:
In the above program
int world = 6; is a Variable Declaration.



◕ Variable Definition:
In order to store data in a variable, we need to have an associated piece of the computer’s memory with that variable name to store the value of that variable. This is called Variable Definition.

But when we declare a variable it automatically contains some computer’s memory.

For an example:
In the above program the statement
int world;
has both a Variable Declaration and a Variable Definition.

If this is the situations then what is the difference between these Variable Declaration and Variable Definition?

The answer is, the difference between these two is that in C++ there are some situations where we have a statement, which is only a Declaration but not a Definition.





Popular Google Pages:





Top of the page

Amazon & Flipkart Special Products

   


Top of the page