Operators in C – tccicomputercoaching.com
- February 24, 2020
- Posted by: Riddhi Dhandha
- Category: Operators in C
What is operator?
Operator means simple symbol which is used between operands (variable) during mathematical process.
There are following categories:
1. arithmetic: + – * / %
printf(“a+b =%d”, a+b);
printf(“a-b =%d”, a-b);
printf(“a/b =%d”, a/b);
printf(“a*b =%d”, a*b);
printf(“a%b =%d”, a%b);
Modulor Operator – % is used in Coding like ro find Number is even or Odd.
printf(“a is even”);
printf(“a is odd”);
2. relational operator : > >= < <= == !=
printf(“a and b are same”);
printf(“a and b are not same”);
3. logical operator : && || !
c.1 c.2 Result c.1 c.2 Result
1. T T T T T T
2. F T F F T t
3. T F F T F t
4. F F F F F F
4. Assignment Operator: =
This operator assign value of right side variable to the left side variable.
i.e int x=10,y=20 ;
5. Increment and decrement: ++ – –
Increment ++ and decrement — to change the value of an operand (constant or variable) by 1. Increment ++ increases the value by 1 whereas decrement — decreases the value by 1. These two operators are unary operators, meaning they only operate on a single operand.
op: 7 6
6. Conditional operator:
Syntax: exp1? exp2:exp3
I.E. int x=10,y=20 ,max;
7. Shorthand Assignment Operator: += +* +/ +%
This statement expnad like x=x+5;
8. Bitwise Operators: & | > <
The Bitwise operators is used to perform bit-level operations on the operands. The operators are first converted to bit-level and then the calculation is performed on the operands. The mathematical operations such as addition, subtraction, multiplication etc. can be performed at bit-level for faster processing. For example, the bitwise AND represented as & operator in takes two numbers as operands and does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1.
Assume variable ‘A’ holds 60 and variable ‘B’ holds 13, then −
(A & B) = 12, i.e., 0000 1100
For more information about C programming at TCCI
Call us @ 9825618292
Visit us @ http://tccicomputercoaching.com/