How to name the variable?
Hello friends today C for fun brings you the differences between variable and constant how to use variable and change their values what is the basic difference between variables and constants that we use in our C programs.
Can values we again and again change in variable?
Can we change the constant this question might arise in your mind go to the blog and you will find all the answers and all doubts would be clear..
How to name the variable?
There are always some basic rules which you have to follow to define the variables if you do not follow the rules then it is always going to show you the error, which gives you a headache only so to avoid all the hassle, follow the rules.
- · A variable name is any combination of alphabets, digits or underscore.
- · The first character must always be alphabet or underscore.
- · No comma or blank space is allowed in special symbols
- · Few examples ac ,cc,c_a.
- · It is important to declare the type of the variable before it is used in the program.
- · constants are the entity or values that do not change during the execution of the program.
Variables are
simply used to refer the memory location,
Constant
A constant
is a value that cannot be changed or altered .for example 1, 5, 2.5,”c language”
An identifier
can be used as a constant
For example
Cost double
pi=3.14
Here pi is
constant and 3.14 are same for this program.
Integer constant:
integer constant is a numeric constant, without any exponential part. These are
of type
Decimal
Octal
Hexadecimal
constant
Character constant:
a character Constant, which use single equation like ‘k’,’l’.
Declaring ,assigning the variable
Below is an example of declaring the integer value,
for any variable
Int n;
Remember to terminate the statement by using semi
colon
The statement means that we
want o store or use n as a variable which would be used to hold integer type of
value.
The four basic data types:
The int type
The integer type of variable
stores the whole numbers value.
For example if an operation
is performed on a number the result you might think 2.568
Then the int type variable
will store value =2
The char type:
With the memory sixe holding
capacity of 1 byte, in c language the char type is used to store character data
as its name suggest.
Example
char =‘a’,’b’;
The float type:
Float variable is used to
store the real numbers, both integer and non integer values. Floating numbers
are the most commonly used for approximation of real numbers and their
operations on them are more efficient on modern microprocessor.
For example:
Float n;
Now n can be used to store
values like 5.2356, which is the advantage over integer.
if you have used the variable of different type and now you need to store the value whichis of differnt type,then you dont need to go and edit you code by changing them where you have declared them ,just do data type casting ,it will allow you to store the value which you want .
these feature in c language make it more user friendly then any other therefore it is the very first choice as prefer by the students!
Comment on your views and if you have any questions out or query you may drop a comment in the comments section they would be reply in no minute.
Share this blog among your friends so that they can also know about the difference which might confuse them.
Comment on your views and if you have any questions out or query you may drop a comment in the comments section they would be reply in no minute.
Share this blog among your friends so that they can also know about the difference which might confuse them.
Leave a Comment