Sie sind auf Seite 1von 4

Due to 16-bit compiler, range of integer is -32768 to 32767

mantissa :- Term before 'e' in exponential expression

Generally maximum allowable length of variable-name is 31 characters. Some compi


lers also support upto 247 characters.

There are 32 keywords(reserve words) in C.

The following statements would work :


int a, b, c, d ;
a = b = c = 10 ;
However, the following statement would not work
int a = b = c = d = 10 ;

C allows only one variable on left-hand side of =. That is, z = k * l is legal,


whereas k * l = z is illegal.

modulus operator (%) cannot be applied on a float. On using % the sign of the re
mainder is always same as the sign of the numerator. Thus 5 % 2 yields 1, whereas,
5 % -2 yields 1.

char a, b, d ;
a = 'F' ;
b = 'G' ;
d = '+' ;
When we do this the ASCII values of the characters are stored in the variables.
ASCII values are used to represent any character in memory. The ASCII values of F
and G are 70 and 71.

For b = 3 ^ 2 ;
#include <math.h>
main( )
{
int a ;
a = pow ( 3, 2 ) ;
printf ( %d , a ) ;
}

Operation Result Operation Result


5 / 2 2 2 / 5 0
5.0 / 2 2.5 2.0 / 5 0.4
5 / 2.0 2.5 2 / 5.0 0.4
5.0 / 2.0 2.5 2.0 / 5.0 0.4

float 30 is stored as 30.000000

Priority Operators Description


1st * / % multiplication, division, modular division
2nd + - addition, subtraction
3rd = assignment

int x, y ;
scanf ( "%d", &x ) ;
y = ( x > 5 ? 3 : 4 ) ;
This statement will store 3 in y if x is greater than 5,
otherwise it will store 4 in y.

The conditional operators can be nested as shown below.


int big, a, b, c ;
big = ( a > b ? ( a > c ? 3: 4 ) : ( b > c ? 6: 8 ) ) ;

&& and || are binary operators, whereas, ! is a unary operator.

main( )
{
int i = 1 ;
while (i <= 10 )
{
printf ("%d\n", i ) ;
i+= 1 ;
}
}

Note that += is a compound assignment operator. It increments the value of i b


y 1. Similarly, j = j + 10 can also be written as j += 10. Other compound assign
ment operators are are -=, *=, / = and %=.

while ( i++ < 10 )


while (++i < 10 )
for ( i = 10 ; i ; i -- )
printf ( "%d", i ) ;
for ( i < 4 ; j = 5 ; j = 0 )
printf ( "%d", i ) ;
for ( i = 1; i <=10 ; printf ( "%d",i++ )
;
for ( scanf ( "%d", &i ) ; i <= 10 ; i++ )
printf ( "%d", i )

main( )
{
int i = 1 ;
for ( ; i <= 10 ; )
{
printf ( "%d\n", i ) ;
i = i + 1 ;
}
}
Here, neither the initialisation, nor the incrementation is done in the for sta
tement, but still the two semicolons are necessary.

main( )
{
int i ;
for ( i = 0 ; i++ < 10 ; )
printf ( "%d\n", i ) ;
}
Here, the comparison as well as the incrementation is done through the same stat
ement, i++ < 10. Since the ++ operator comes after i firstly comparison is don
e, followed by incrementation. Note that it is necessary to initialize i to 0

main( )
{
int i ;
for ( i = 0 ; ++i <= 10 ; )
printf ( "%d\n", i ) ;
}
Here, both, the comparison and the incrementation is done through the same state
ment, ++i <= 10. Since ++ precedes i firstly incrementation is done, followed b
y comparison. Note that it is necessary to initialize i to 0.
{
m = r + c ;
printf ( "r = %d c = %d sum = %d\n", r, c, sum ) ;
}
Instead of using two statements, one to calculate sum and another to print it ou
t, we can compact this into one single statement by saying:
printf ( "r = %d c = %d sum = %d\n", r, c, r + c ) ;

for ( i = 1, j = 2 ; j <= 10 ; j++ )


Use of multiple statements in the initialisation expression also demonstrates wh
y semicolons are used to separate the three expressions in the for loop. If com
mas had been used, they could not also have been used to separate multiple state
ments in the initialisation expression, without confusing the compiler.

/* Execution of a loop an unknown number of times */


main( )
{
char another ;
int num ;
do
{
printf ( "Enter a number " ) ;
scanf ( "%d", &num ) ;
printf ( "square of %d is %d", num, num * num ) ;
printf ( "\nWant to enter another number y/n " ) ;
scanf ( " %c", &another ) ;
} while ( another == 'y' ) ;
}
And here is the sample output...
Enter a number 5
square of 5 is 25
Want to enter another number y/n y
Enter a number 7
square of 7 is 49
Want to enter another number y/n n
In this program the do-while loop would keep getting executed till the user cont
inues to answer y. The moment he answers n, the loop terminates, since the condi
tion ( another == 'y' ) fails. Note that this loop ensures that statements with
in it are executed at least once even if n is supplied first time itself.

Das könnte Ihnen auch gefallen