Introduction to C Language and Programming (Part IV, More about Variables and Operators
When we are declaring a variable, we should know about the
art of the programming. We can declare a variable like below.
Int a;
And we can assign some values as to the variable and run it.
There is an example which I am going to explain below.
#include
<stdio.h>
int
main()
{
int a;
a=55;
a=100;
a=65;
a=500;
printf("The Number is :
%d",a);
getchar();
return 0;
}
Here we have assigned some values to the Variable a few times and what will be the
result?
When reading and printing code, basically using this kind of
computer program code, it will take the final value as the result, as a result of
that the answer will be 500,
so printf function will display 500 here.
There some other you should know about programming. I have
declared a variable and assign some values below.
Int
a =100;
a
= a +200;
You know the answer is 300.
And also you can do it like below, and it will be the same
answer
Int
a=100;
a
+ = 200;
The answer is also 300.
You can try, there are two examples which I have given you
below and understand it.
Example 1:
#include
<stdio.h>
int
main()
{
int a = 100;
a = a + 200;
printf("The Number is :
%d", a);
getchar();
return 0;
}
Example 2:
#include
<stdio.h>
int
main()
{
int a = 100;
a = a + 200;
printf("The Number is :
%d", a);
getchar();
return 0;
}
As above, we
can use it with other operators also.
+
=
-
=
/
=
*
=
These operators
are more useful
a = a +1;
a + = 1;
b = b * 1;
b * = 1;
c = c / 2;
c / = 2;
d
= d – 2;
d
- = 2;
Now you know
how to use them and try those with your own codes.


0 comments:
Post a Comment