Introduction Data type Variable-Constant Keyword-Identifier Operations Input&Output If-else Switch loops String Array Functions Recursion-Function Mat-Function Pointers File handling Read & write Error handling Read & write error handling


Operators

Operators are the symbols that can be used to perform mathematical operations such as addtion, substration, relational, bitwise, conditional etc..


Arithmetic Operators


This are used to perform mathematical operations on numerical values, such as integers and floating-point numbers


Operator Description example
+ Addition a+b
- Subtraction a-b
* Multiplication a*b
/ Division a/b
% Modulus (Remainder) a%b
Example
 
#include <stdio.h>

 int main() {
 int num1 = 10;
 int num2 = 5;
                        
 int sum = num1 + num2;  
 int difference = num1 - num2;
 int product = num1 * num2;
 int quotient = num1 / num2;
                        
 printf("Sum: %d\n", sum);
 printf("Difference: %d\n", difference);
 printf("Product: %d\n", product);
 printf("Quotient: %d\n", quotient);
                        
 return 0;
                  
      }
                

Output
            Sum is : 15
            Difference is : 5
            Product is : 50
            Quotient is: 2
                

Relational Operator

Relational operators in C are used to compare two values and determine the relationship between them


Operator Description example
< a is less than b a
<= a is less than or equal b a <=b
> a is greater than b a>b
>= a is greater than or equal a>=b
== equal-to operator a==b
!= not-equal operator a!=b

Here we only testing two values if right menas prints 1 else 0.


Example
 
#include <stdio.h>

 int main() {
 int C = 10;
 int Java = 5;
     
//use equal operator if this conditon true means print output as a 1 else 0   

 printf("%d", C==Java); 
 //same this also but operator only chage if true means print output as a 1 else 0
 
 printf("%d", C>Java); 
 printf("%d", C>=Java);              
 printf("%d", C<=Java);              
           
 return 0;
   
            }
                

Output
            Not equal 0
            qual 1
            equal 1
            Not equal 0
            

Useing if..else statement in this concept will discusess in detail in upcoming page


Example
 
#include <stdio.h>
 int main()
    {
 int C = 10;
 int Java = 5;
 printf("Condition checking\n");
 // Equal to (==) operator
 if (C == Java) {
   printf("%d i equal to %d\n", C, Java);
        } 
 else if (C!=Java)
        {
   printf("%d is not equal to %d\n", C, 
        Java);
        }
        
 else {
     printf("%d not matching given condition %d\n", C, Java);
      }
       return 0;
    }
  

Output
             Condition checking
             10 is not equal to 5
            

Increment & Decrement Operator

Increment and decrement operators in C are used to increase or decrease the value of 1 to the operand

Operator Description example
++ add 1 number ++a
-- decreas 1 number --a

Example
 
#include <stdio.h>
 int main()
   {
 int age ,age1;
 age = 10;
 // Here increase the 1 number using Increment operator. 
 age1=++age; 
 printf("The original age is %d\n" ,age);
 printf("After increase the 1 to original 
       age : %d\n", age1);
    
  return 0;
   }


Output
            The original age is 11
            After increase the 1 to original age : 11
            
Open kannada !





@2022, Padma Education.

We cannot warrant full correctness of all content, we try to give our best. While using Padma education website, you agree to have read and accepted our terms and Conditions , privacy policy.