1. Operators in c programming
Name : Krishna kumar Pankaj
Roll No : 13/IT/22
2. What is Operators ?
๏ต An operator is a symbol that is used to perform certain mathematical or
logical operations.
๏ต Operator is used to manipulate data and variables.
3. Types of operators
๏ต In C programming Operators classified in to various categories
๏ต 1. Arithmetic operators
๏ต 2. Relational operators
๏ต 3. Logical operators
๏ต 4. Assignment operators
๏ต 5. Increment & Decrement operators
๏ต 6. Conditional operators
๏ต 7. Bitwise operators
๏ต 8. Special operators
4. Arithmetic operators
๏ต Arithmetic operators used to perform Arithmetic operations.
๏ต There are following Arithmetic operators in c language
5. Example :
๏ต #include<stdio.h>
#include<conio.h>
int main()
{
int x=25;
int y=5;
printf("%d+%d=%dn",x,y,x+y);
printf("%d-%d=%dn",x,y,x-y);
printf("%d*%d=%dn",x,y,x*y);
printf("%d/%d=%dn",x,y,x/y);
getch();
}
๏ต Output :
25+5=30
25-5=20
25*5=125
25/5=5
6. Relational operators
๏ต Relational operators compare between two operands and return in terms of
true or false
๏ต There are following Relational operators.
7. Example :
#include<conio.h>
#include<stdio.h>
int main()
{
int a, b;
printf("Enter values for a and b : ");
scanf("%d%d",&a,&b);
printf("n The < value of a is %d", a<b);
printf("n The <= value of a is %d", a<=b);
printf("n The > value of a is %d", a>b);
printf("n The >= value of a is %d", a>=b);
printf("n The == value of a is %d", a==b);
printf("n The != value of a is %d", a!=b);
getch();
๏ต }
8. Logical operator
๏ต A Logical operator is used to compare or evaluate logical or relational
operations.
๏ต There are following logical operators
10. Assignment operator
๏ต An Assignment operator is used to assign a constant or a value of one
variable to another.
๏ต = is an Assignment operator.
๏ต you can use the assignment for multiple assignment as follows:
๏ต x=y=z=20;
11. Increment Operator(++)
๏ Increment operator are increase the value of subsequent
๏ Increment operator are two types as follows:
โข post Increment
โข Ex : x=5;x++;x=5
โข pre Increment
โข x=5;++x;x=6
12. Decrement operator(--)
๏ต Decrement operator Decrease the value to one ,two and so on.
๏ต Decrement operator are also two type as
โข Post Decrement
โข x=5;x--;x=5
โข pre decrement
โข x=5;--x;x=4
13. Example of Increment & Decrement
operator
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
printf("Enter the values for a and b :");
scanf("%d%d", &a, &b);
printf("n The value of c is %d", c=++a);
printf("n The value of c is %d", c=a++);
printf("n The value of c is %d", c=--b);
printf("n The value of c is %d", c=b--);
}
๏ต Output
Enter the value of a and b : 3 ,7
The value of c is 4
The value of c is 4
The value of c is 6
The value of c is 6
14. Conditional operator
๏ They are also called as ternary operator.
๏ They are also called as ?: operator.
๏ Ternary operator Takes on 3 Argument
Where
1) Expression 1 is condition
2) Expression2 is Statement Followed if Condition is True
3) Expression2 is Statement Followed if Condition is False
True
Condition ? Block 1 : Block 2
False
16. Bitwise Operator
๏ต One of the C powerful Features is a set of bit manipulation operators
๏ต There are various Bitwise Operators in C as following Table.
1. & (bitwise AND) Takes two numbers as operand and does AND on every bit of
two numbers. The result of AND is 1 only if both bits are 1.
2. | (bitwise OR) Takes two numbers as operand and does OR on every bit of two
numbers. The result of OR is 1 any of the two bits is 1.
3. ^ (bitwise XOR) Takes two numbers as operand and does XOR on every bit of
two numbers. The result of XOR is 1 if the two bits are different.
4. << (left shift) Takes two numbers, left shifts the bits of first operand, the
second operand decides the number of places to shift.
5. >> (right shift) Takes two numbers, right shifts the bits of first operand, the
second operand decides the number of places to shift.
6. ~ (bitwise NOT) Takes one number and inverts all bits of it
17. Special Operator
๏ต There are many special operators use in c programming.
๏ต Comma operator
๏ต Sizeof Operator
18. Comma Operator
๏ต Evaluate of comma operator โ Left to Right
๏ต Uses of comma operator as following :
๏ต Multiples Declaration
๏ต Multiples Initialization
๏ต Multiples Variation
๏ต Multiples Statement
๏ต Example of comma operator
๏ต X=12,y=10,z=18
๏ต For( i=0,j=0;i<5,j<5;i++,j++ )
19. Sizeof operator
๏ต Sizeof operator calculate the size of data
๏ต i.e: How many bit a specific data having.
๏ต Syntax of sizeof operator:
๏ต Sizeof(variable);
Example :
sizeof(a), where a is interger, will return 4
20. Thank you
Any Queries ???
Go to Google Or
Email me at โKrishna.pankaj@hotmail.comโ