Q . What is the difference between declaring a variable and defining a variable in programming?Mike Tyson. asked, Aug 16 ' 2017
What is the actuall meaning of these in programming.
Declaring a variable:
Declaration of a variable in C hints the compiler about the type and size of the variable in compile time. No space is reserved in memory for any variable in case of declaration. Declaration of a variable serves two purposes: It associates a type and an identifier (or name) with the variable.
Example: int a;
Here variable 'a' is declared of data type 'int'
Defining a variable:
Defining a variable means declaring it and also allocating space to hold it. We can say "Definition = Declaration + Space reservation". Definition of variable mean asking compiler to allocate memory to variable or define storage for that variable.
Example: int a = 10;
Here variable "a" is described as an int to the compiler and memory is allocated to hold value 10.
Simply, what it does?
1. Declaration will identify the data type of the identifier.
2. Definition of the variable will assign some value to it.