A variable in simple terms is a storage place which has some memory allocated to it. Basically, a variable used to store some form of data. Different types of variables require different amounts of memory and have some specific set of operations which can be applied to them.
Variable Declaration:
A typical variable declaration is of the form:
A typical variable declaration is of the form:
type variable_name; or for multiple variables: type variable1_name, variable2_name, variable3_name;
A variable name can consist of alphabets (both upper and lower case), numbers and the underscore ‘_’ character. However, the name must not start with a number.
Difference b/w variable declaration and definition
The variable declaration refers to the part where a variable is first declared or introduced before its first use. A variable definition is a part where the variable is assigned a memory location and a value. Most of the times, variable declaration and definition are done together.
The variable declaration refers to the part where a variable is first declared or introduced before its first use. A variable definition is a part where the variable is assigned a memory location and a value. Most of the times, variable declaration and definition are done together.
See the following C program for better clarification:
Output:
a
Is it possible to have a separate declaration and definition?
It is possible in case of extern variables and functions.
It is possible in case of extern variables and functions.
No comments:
Post a Comment