-:OPERATORS:-
Definition :-
Ex:- z=x+y;
Unary :- it takes 1 operand only
Binary :- it takes 2 operands
Ternary :- it takes 3 operands
Example :
z=x+y; z = -10 ;
z = +10; z=x–y;
-:TYPE OF OPERATORS:
1. Arithmetic’s operator
-, +,*, /,%
(Unary) (Binary)
% operator It always return remainder.
Ex:-
z = 17%5 ; z = 15 % 3 ;
z = 90%7; z = 20 % 4 ;
2:- Relational operator:-
> , <, >= , <=, == , !=
Note:-
Boolean value
True False
T F
1 0
Non zero zero
EX:- int X=10 ;
( X > 10 ) ( x == 10 )
( X < 10 ) ( x == 5 )
( X >= 10 ) ( x != 10 )
( X <= 10 ) ( x != 5 )
Special cases :
Int x = 25 ;
( X => 10 )
( X > =10 )
3:- Logical operator
&& Logical AND
|| Logical OR
! Logical NOT
Defination:- Logical operator are applied between 2 relational
expression and return Boolean value.
Truth table for && Truth table for | | Truth table
for !
int x=12, y=5, z=7 ;
( x > y && z != 15 ) ( x > y || z != 15 ) !( x > y )
( x > y && z != 7 ) ( x > y || z != 7 ) ! ( x == y )
( x== y && z != 15 ) ( x== y || z != 15 ) ! ( ! ( x != y ) )
( x== y && z != 7 ) ( x== y || z != 7 ) ! ( ! ( z != y ) )
Example :
Note:- Logical AND does not checks II exp if I exp is false
Logical OR does not checks II exp if I exp is true
4:- Increment / Decrement operators
++( increment by 1) -- ( decrement by 1)
int X=5 ; int X=5 ;
X++ ; X- - ;
++X ; --X ;
Note : prefix and postfix version are same , if we are using
individually , but if we are using these operators with other
operators , the precedence will be different .
Example ;
int X=5 ; int X=5 ;
C = X++ ; C = ++X ;
C= C=
X= X=
Note : In following expressions which expression is better and why ?
int X=5;
X++; or X=X+1;
5: - Assignment operator
= (Bitwise Assignment operator)
+ = , -=, *=, /= (Shorthand assignment operator)
int X=5;
X = 10 ;
X += 4 ;
X -= 12 ;
X *= 7 ;
X /= 2 ;
Example :
6 :- Bitwise operator
& Bitwise and
| Bitwise inclusive or
^ Bitwise inclusive or
>> Right shift operator
<< Left shift operator
&=, |=, ^= , >>=, <<= ( bitwise short hand
assignment operators )
8 :- Conditional operator
?: (ternary operator)
X = 10,Y = 5,Z;
Z= (X>Y) ? 100: 200;
Example:-
Exercise
int x = 5 ;
X*= X++ + ++X + X++ + ++X + X;
FLOW CHART OF “C” PROGRAM
Start
Load c
Edit program
compile
Run
O/P
Exit
-: types of error:-
1:- Compile time error/ syntax error
2:- Run time error/ logical error
< stdio.h > Standard Input Output Hearder File : - It contain all
functions related to input /output operations .
Note : In any computer language the name of function is
always followed by open and close Parenthesis ‘( )’ .
Printf( ):-It is a formatted function of < stdio.h > header file which
is used to print some message or valves on moniter..
Ex: 1 ) - printf ( “Hello India ” );
O/P :- Hello India
formatted specifiers /characters in “C”
Datatype Specifiers
int %d, %i
char %c
float %f
string %s
unsigned int %u
long int %ld
double %lf
long double %Lf
Ex 2 ) - int X=5;
char Y=’A’;
float Ch=10.5;
printf ( “%d %f %c” , X , Ch , Y );
O/P 5 10.5 A
Ex 3 )- printf ( “Average = %f ” , avg );
O/P: Average = 27 . 8
scanf( ) :- It is a formatted function of <stdio.h> header file which
is used to scan or enter Some values from keyboard on moniter.
Ex:-
int X;
char Ch;
float Y;
Scanf ( “%d%f%c” , &X , &Y,&Ch);
Basic structure
//WAP to calculate the addition of two no:-.
#include<stdio.h>
void main( )
{
int x , y , z ; //decleration of variable
printf (" enter x and y ");
scanf ( "%d%d" , &x , &y );
printf ( " the sum of n=%d " , z );
}
Basic concept for executing programs:
• SAVE with .c extension (in user directory)
• COMPILE = F9
• RUN = Ctrl+F9
• O/P = Alt+F5 ( to shift control to outpur window or console )