Unit-3 Operators and IO Statements
Unit-3 Operators and IO Statements
Arithmetic operators
Relational Operators
Equality Operators
Logical Operators
Unary Operators
Conditional Operators
Bitwise Operators
Assignment operators
Comma Operator
Sizeof Operator
ARITHMETIC OPERATORS
Multiply * a * b result = a * b 27
Divide / a / b result = a / b 3
Addition + a + b result = a + b 12
Subtraction - a - b result = a – b 6
Modulus % a % b result = a % b 0
A B A &&B A B A || B A !A
0 0 0 0 0 0
0 1
0 1 0 0 1 1
1 0 0 1 0 1
1 0
1 1 1 1 1 1
UNARY OPERATORS
| bitwiseOR LefttoRight
~ 1’sComplement LefttoRight
^ bitwiseExclusiveOR LefttoRight
Expression Bits
a=12 001100
b=9 001001
c=a&b 001000
c=a|b 001101
ASSIGNMENT OPERATORS
float x;
int y = 3;
x = y;
Now, x = 3.0,
TYPE CONVERSION AND TYPE CASTING
length Description
Output
_ Consider _ _12345 _ _12345.00 __ _ _A
as Space
Here 10.2f
Here there are 5 digits specifies 7 digits
Here 5c specifies the
and %7d leaves two + decimal + 2
Description position of the
blank space before the 5 values in
digit number precision after character to be printed
decimal point
printf()
Output:
#include<stdio.h>
#include<conio.h>
void main()
12.35
{
float num=12.346; 12.35_ _ _ _ _
clrscr();
0012.35
printf(“\n %5.2f”,num);
printf(“\n %-10.2f”,num);
printf(“\n %07.2f”,num);
getch();
}
scanf()
The scanf() is used to read formatted data from the
keyboard. The syntax of the scanf() can be given as,