What is the difference between variable declaration and variable definition? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

What is the difference between variable declaration and variable definition?

15th Jun 2016, 10:54 AM
Boris Atanasov
Boris Atanasov - avatar
3 Answers
+ 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
15th Jun 2016, 12:37 PM
VIPUL RINWA
VIPUL RINWA - avatar
+ 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;
12th Jan 2017, 2:18 AM
Aaron Sbarra
+ 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. 😋😊😏
25th Jan 2017, 3:33 AM
Rohan Singh
Rohan Singh - avatar