+ 5
What is the difference between variable declaration and variable definition?
3 odpowiedzi
+ 6
variable declaration means initializing memory for a variable.
And variable definition means initializing value or expression to a variable
for eg.
int a; //variable declaration
a=7;
a=b-c. //these are variable definition
+ 3
Declaration is where you initialize, or set aside memory for a variable
Eg. int x;
definition is where you actually assign a value to the variable
Eg.
x = 0;
In C++, when you declare a variable, no default value is given. so if you attempt to use the variable before it gets defined, bad things happen. Some languages, like Java, will give a variable an initial value when it gets declared.
You can also combine declaration and definition into one line:
int x = 0;
+ 2
Variable Declaration means initializing memory for a variable or in short creating a variable while Variable Definition means initializing value to a variable
for eg.
int x; //variable declaration as here I created the variable
x=11; //these are variable definition as I assigned value to my variable.
Now let me show a typical case when variable declaration And variable definition are done together.
eg.
int x=11;
Thank you for reading this long answer.
P.S. Don't forget to Upvote this. 😋😊😏