# Operators

9. May 2016
1 von 20

### Operators

• 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
• 9. Example : #include<stdio.h> #include<conio.h> int main() { int a, b; printf("Enter values for a and b : "); scanf("%d%d", &a, &b); printf("n %d",(a<b)&&(a!=b)); printf("n %d",(a<b)||(b<a)); printf("n %d",!(a==b)); getch(); }
• 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
• 15. Example : #include<stdio.h> void main() { int a, b, x; printf("Enter the values of a add b : "); scanf("%d %d", &a, &b); x=(a>b)?a:b; printf("Biggest Value is :%d",x); }
• 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”