Search This Blog

Blog Inauguration By : Prof. N. L. Vijaykumar, INPE - Brazil

CSE

OPERATORS

OPERATORS IN C

In C programming, operators are classified into several categories based on their functionality. Here are the types of operators in C with a brief explanation and syntax:

Arithmetic Operators:

Arithmetic operators are used for performing arithmetic operations like addition, subtraction, multiplication, division, and modulus. Here's the list of arithmetic operators in C:

Operator     Description  
Addition                     a + b
Subtraction                 a - b
Multiplication             a * b
Division                      a / b
Modulus                      a % b

syntax:
Addition Operator (+): Syntax: operand1 + operand2
Subtraction Operator (-): Syntax: operand1 - operand2
Multiplication Operator (*): Syntax: operand1 * operand2
Division Operator (/): Syntax: operand1 / operand2
Modulus Operator (%): Syntax: operand1 % operand2

Relational Operators:

Relational operators are used for comparing two values. They return either true or false. Here's the list of relational operators in C:

Operator       Description             Example
    ==                Equal to                            a == b
    !=                Not equal to                    a != b
     >                       Greater than                         a > b
     <                       Less than                              a < b
    >=                     Greater than or equal to        a >= b
    <=                      Less than or equal to            a <= b

syntax:
bool result = operand1 operator operand2;

For example, to add two numbers:
Equal to Operator (==): Syntax: operand1 == operand2
Not equal to Operator (!=): Syntax: operand1 != operand2
Greater than Operator (>): Syntax: operand1 > operand2
Greater than or equal to Operator (>=): Syntax: operand1 >= operand2
Less than Operator (<): Syntax: operand1 < operand2
Less than or equal to Operator (<=): Syntax: operand1 <= operand2

Logical Operators:

Logical operators are used to perform logical operations on boolean expressions. Here's the list of logical operators in C:

Operator      Description          Example
&&                   Logical AND       a && b
||                        Logical OR          a || b
!                        Logical NOT        !a

Syntax:
AND Operator (&&): Syntax: condition1 && condition2
OR Operator (||): Syntax: condition1 || condition2
NOT Operator (!): Syntax: !condition

Bitwise Operators:

Bitwise operators are used to perform operations on individual bits of a variable. Here's the list of bitwise operators in C:

Operator      Description     Example
&                       Bitwise AND             a & b
|                       Bitwise OR                 a | b
^                       Bitwise XOR             a ^ b
~                       Bitwise NOT              ~a
<<                       Left Shift                     a << n
>>                          Right Shift                    a >> n

Syntax:
&  ;  Bitwise AND ; operand1 & operand2
|    ;  Bitwise OR    ; operand1 | operand2
^   ;  Bitwise XOR ; operand1 ^ operand2
~  ;   Bitwise NOT (one's complement) ; ~operand
<<;  Left shift        ; operand << number_of_bits
>>;  Right shift      ; operand >> number_of_bits

Assignment Operators:

Assignment operators are used to assign values to variables. Here's the list of assignment operators in C:

Operator      Description                Example
=                Simple assignment                      a = b
+=                Add and assign                            a += b  (same as a = a + b)
-=        Subtract and assign                    a -= b  (same as a = a - b)
*=        Multiply and assign                    a *= b (same as a = a * b)
/=        Divide and assign                    a /= b  (same as a = a / b)
%=        Modulus and assign                    a %= b  (same as a = a % b)
&=                Bitwise AND and assign            a &= b (same as a = a & b)
|=                Bitwise OR and assign            a = b (same as a = a | b)
^=                Bitwise XOR and assign            a ^= b (same as a = a ^ b)
<<=                Left Shift and assign            a <<= n (same as a = a << n)
>>=                Right Shift and assign                 a >>= n (same as a = a >> n)

Syntax:
Simple Assignment Operator (=)             : Syntax: variable   = value
Addition Assignment Operator (+=)        : Syntax: variable += value
Subtraction Assignment Operator (-=)     : Syntax: variable  -= value
Multiplication Assignment Operator (*=): Syntax: variable *= value
Division Assignment Operator (/=)          : Syntax: variable  /= value
Modulus Assignment Operator (%=)       : Syntax: variable%= value

No comments:

Post a Comment