Operators And Separators In C Language Operators in C Language:


Below are various operators available in C Programming language.  They are used to perform operations arithmetic, logical, relational, bitwise, assignment, etc.  We will see more about all the below operators in details in the forth coming chapters.

Operators Name Of Operators
[ ]
( )
.
->
++ -- Array subscript
Function Call
Structure reference
Structure dereference
Postfix increment/Postfix decrement
++ --
+ -
! ~
(type)
*  &
sizeof Prefix increment/Prefix decrement
Unary plus/Unary minus
Logical negation/One's complement
Typecast operator
Pointer dereference/Address of
Size of type/variable in bytes
*  /  % Multiplication/Division/Modulo
+ - Addition/Subtraction
<<   >> Bitwise left shift/ Bitwise right shift
<    >
<=
>= Comparison less than/Comparision greater than
Comparison less than or equal to
Comparison greater than or equal to
==   != Comparison equal to/Comparison not equal to
& Bitwise AND
^ Bitwise XOR
| Bitwise OR
&& Logical AND
|| Logical OR
?: Ternary Conditional Operator
=
*=    /=   %=
+=    -=
<<=   >>=
&=    ^=
|= Assignment Operator
Mulplication/division/modulo assignment
Addition/Subtraction assignment
Bitwise left shift/right shift assignment
Bitwise AND/XOR assignment
Bitwise OR assignment
, Comma Operator

What is separator in C?
Separator is used to separate tokens.  Below are the various separators available in c language.

;  ,  .  :  ( )  [ ]  { }
Note:  White space is also a separator, but it is not a token.

Let us write a C program using some separators and arithmetic operators.


  #include <stdio.h>
  int main() {
        int a = 100, b = 20, res;
        res = a + b;
        printf("Sum: %d\n", res);
        res = a * b;
        printf("Product: %d\n", res);
        res = a - b;
        printf("Difference: %d\n", res);
        res = a / b;
        printf("Div: %d\n", res);
        return 0;
  }

  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Sum: 120
  Product: 2000
  Difference: 80
  Div: 5

+, -, /, *   are the operators used in above C program
{ } (  ) , ; are the separators used in above C program

Comments

Popular posts from this blog

Difference between asterisk and ampersand operators in c