Monday, 13 April 2020

Section 2d Operators in C

C Operators  

1. Arithmetic operators

The Arithmetic Operators in C: To perform Mathematical operations/calculations like  calculations like addition (+), subtraction (-), multiplication (*), division (/) and modulus (%).

  1.  + (Addition) – To add two operands.
  2. – (Subtraction) –  To Subtract two operands.
  3. * (Multiplication) – To Multiply two operands.
  4. / (Division) – Divide two operands and gives the quotient as the answer.
  5. % (Modulus operation) – Gives the remainder after the division.
  6. ++ (Increment) –To increment an operand.
  7. — (Decrement) – To decrement an operand
  ref testarithmetic.c

2 .Relational Operators

Used to compare 2 numbers or quantities


==, !=,  >, < , >=, <=


  ref testrelational.c

3. Logical Operators : Used to test more than one condition to make decisions. These are && (AND) , ||(OR)  , !  (Not)

ref testlogical.c

4.   Bitwise operators : They are used for  manipulating data at bit level

Bit wise operators in C:These operators are used to perform bit operations
&      Binary AND Operator
^      Binary XOR Operator
|        Binary OR Operator
<<    Binary Left Shift Operator
>>    Binary Right Shift Operator
~       Binary Ones Complement Operator

ref: testbitoperator.c

5. Assignment operators : 

These are used to assign values to variables.

=         Assign the vale
+=      Increment the variable by the value  and assign
-=        Decrement the variable by the value and  assign
*=        Multiplie then assign
/=        Divides then assign
%=      Modulus then assign
<<=    Left shift and assign
>>=    Right shift and assign
&=       Bitwise AND assign
^=       Bitwise exclusive OR and assign
|=        Bitwise inclusive OR and assign

6. Conditional operator

The Conditional Operator in C, is  used in the decision-making process in place of  conditional statements if and else statement, to replace a short if else statement in c

Syntax of ternary operator

condition ? value_if_true : value_if_false

ref: testtern.c

7. Special operator 

& operator is used to get the address of the variable
* operator stores or points to the address of another variable
sizeof() is a compile-time operator that determines the size of variable in bytes
 



ref testspecop.c






No comments:

Post a Comment