Introduction

Arithmatic Operators

Binary Operator
Operator Name Operator Symbol Expression
Addition: + 2*3+5-10/3
Subtraction: - -1+3*25/5-7
Division: / distance/time
Multiplication: * 3.14*radius*radius
Modulus: % 37%10
Unary operators
Operator Name Operator Symbol Expression
plus: + a++
Minus: - --a

Example

Suppose x and y are two integer variables,whose values are 16 and 5 respectively

x+y 21
x-y 11
x*y 80
x/y 3
x%y 1
++x 17
y-- 5

All operators except % can be used with operands of all of the data types int, float, double, char (yes! char also! We will see what it means later)
% can be used only with integer operands
If all operands of an operator are integer(int variables or integer constants),thevalue is always integer

  Example:9/5 will be 1, not 1.8
  int a=9, b=5;
  printf("%d", a/b);
  will print 1 and not 1.8

If at least one operand is real, the value is real
Caution:Since floating-point values are rounded total number of significant digits permissible,the final value is an approximation of the final result
Example:1/ 3.0 * 3.0 may have the value 0.99999 and not 1.0

Assignment Operators

More Assignment Operators

Logical Operators

Operation
a b a&&b a||b
0 0 0 non-0
0 non-0 0 non-0
non-0 0 0 non-0
non-0 non-0 non-0 non-0

Logical Expressions

((count <= 100) || (count>= 200))
((math+phys+chem)/3 >= 60)
((sex == 'M') && (age >= 21))
((marks >== 80) && (marks < 90))
((balance > 5000) | | (no_of_trans > 25))
(!(grade == 'A'))

Unary negation operator (!)

Example

Increment and Decrement Operators

pre-increment v/s post-increment

Relational Operators

Relational Operators Symbol & Name

Used to compare two quantities.

Symbol Name
< is less than
> is greater than
>= is less than or equal to
>= is greater than or equal to
== is equal to
!= is not equal to

Examples:

10 > 20 is false, so value is 0
25 < 35.5 is true, so value is 1
12 > (7 + 5) is false, so value is 0
32 != 21 is true, so value is 1

When arithmetic expressions are used on either side of a relational operator, the arithmetic expressions will be evaluated first and then the results compared a + b > c - d is the same as (a+b) > (c+d).

Bitwise Operators

Note:For calculating two operand with Bitwise operator convert number firstly into binaray number afterthat apply operation on every single bits according to below mention table.

Operand-1 Operand-2 Operand-1 &(Bitwise AND) Operand-2 Operand-1 |(Bitwise OR) Operand-2 operand-1 ^(Bitwise XOR) operand-2
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0

Type Casting

Illustration 3.1
  #include<stdio.h >
    int main() {
    int a = 25, b = 10;
    float result;
    result = a/b;
    printf("The result is %f\n", result);
    return 0;
}
       
        Output:The result is 2.000000
       
    Illustration 3.2
    #include<stdio.h >
    int main() {
    int a = 55, b = 10;
    float result;
    result = (float) a/b;
    printf("The result is %f\n", result);
    return 0;
    }
          
    output:The result is 5.500000
  
Illustration 3.3
int main() {
int a = 25;
float b = 10.0;
float result;
result = a/b;
printf("The result is %f\n", result);
return 0;
}
        Output:The result is 2.500000
      

Statements in C

Parts of C program that tell the computer what to do

example

A Special Operator: AddressOf (&)

      int a =10;
      printf("Value of a is %d, and address of a is %d\n", a, &a);
      

Expression Evalation Order of Operator & Associativity Table

Chapter 3 Quiz

1.Associativity of C Operators *, /, %, <<=, * and=is
2.Can you use C Modulo Division operator (%) with float and int?
3.What number system is not understood by C language compiler directly.?
4.What is the output of Exclusive OR ^ operator on 0110^1000.?
5.What is the Bitwise operator used to make 1's Compliment.?
Home Page
Top of Page
Go Next
Go Next