1) We have discussed the structure of a C program in previous section.Now let us discuss about variables and arithmetics in this section
2)There
are two types of variables global variables, local variables.In C, all
variables must be declared before
they are used in the program.
3)
A declaration announces the properties of variables; it consists of a name and
a list of variables, such as
int
add,sub;
int top,bottom;
In
the above one int means integer type which takes any constants like add =4 if
we give int add=2.2 there will be an error which says wrong declaration, we
have to give correct declaration for variables
4)Unlike
integer(int),there are some types they are
Character(char)--which
prints a single character constant this should be declared in '' this way
Float(float)--which
prints floating point constant suppose if we divided 12 by 32 the result will
be
0.375,and
we store this value to c by giving int type then we get answer as 0 because it
will
not
consider the numbers after the point if
we give float type it gives the exact answer
So
these are important data types there are some more like double,string which we
discuss later
4)To
detect this types by the compiler we have following things
%d
print as decimal integer
%c
prints as character
%s
prints character string
%6d
print as decimal integer, at least 6 characters wide
%f
print as floating point
%6f
print as floating point, at least 6 characters wide
%.2f
print as floating point, 2 characters after decimal point
%6.2f
print as floating point, at least 6 wide and 2 after decimal point
5)Next
we come to arithmetic expressions these are known to every one the arithmetic
expressions are like addition(+),
subtraction(-),multiplication(*),division(/).
6)These
expressions are very familiar to all so these expressions can be used in the C
programming but multiplication and division have a higher prescedence than
addition
and subtraction
No comments:
Post a Comment