Jun 23
Variables
As a programmer, you will frequently want your program to “store” a value. For example, if your program requests a value from the user, or if it calculates a value, you will want to store it somewhere so you can use it later. The way your program store or remember things is by using variables. For example:
int b; //definition
The Above Line "Says I want to create a space for b and that stores an integer value"
,it will allocate the memory to b and initialize the garbage value that's is why it
is known as variable definition.
// it is a comment ,which the c compiler will not process and it is known as single Line comment.
Now store a value in variable b which exits in the memory allocated to the variable b
as :
b=5;
therefore,we define a variable as an identifier whose value changes from time to time during execution.
It is a named data storage location in computer memory.
All variables have 3 essential attributes
- the name.
- the value.
- the memory,where the value is stored
In C, there are several standard types for variables:
- int – integer (whole number) values
- float – floating point values
- char – single character values (such as “m” or “Z”)
Declaring a Variable :
syntax: data type variable-name;
Example
int a;
char code;
Initializing a Variable :
When variables are declared,values can be assigned to them into two ways:
- Within type decleration
example:
int a = 10;
float b= 0.4e-5;
char c= ‘a’;
2. Using assignment statement
example
int a;
a=10;
float b;
b=0.4e-5;
written by Shweta
\\ tags: Variables
Recent Comments