ASSIGNMENT OPERATOR IN C

Maha



Assignment Operator In C

The assignment operator (=) in C programming is used to set a variable's value. It stores the value in the variable on its left side after it taking from its right side. The following examples show how to use the assignment operator:

Assignment Operators Are:

   =    Simple assignment
 +=    Addition assignment
  -=    Subtraction assignment
 *=    Multiplication assignment
  /=    Division assignment
%=    Modulo assignment


Example For Simple Assignment Operator:

Program:


  #include<stdio.h>
  int main() {
  int x;
  x = 14; 
  printf("The value is: %d",x);
  return 0;
  }


Output:


  The value is: 14


Example For Addition Operator With Assignment:

Program:



  #include<stdio.h>
  int main() {
    int x = 5;
    x += 3;
    printf("The value of += addition operation: %d\n", x); 
 }


Output:



  The value of += addition operation: 8



Example For Subtraction Operator With Assignment:

Program:


  
  #include<stdio.h>
  int main() {
    int x = 10;
    x -= 2;
    printf("The value of subtract operation: %d\n", x); 
  }


Output:



  The value of subtract operation: 8



Example For Multiplication Operator With Assignment:

Program:



  #include<stdio.h>
  int main() {
    int x = 5;
    x *= 4;
    printf("The value of *= multiplication operation: %d\n", x); 
  }


Output:



  The value of *= multiplication operation: 20



Example For Division Operator With Assignment:

Program:



  #include<stdio.h>
  int main() {
    int x = 15;
    x /= 5;
    printf("The value of /= division operation: %d\n", x); 
  }


Output:



  The value of /= division operation: 3
 


Example For Modulo Operator With Assignment:

Program:


  
  #include<stdio.h>
  int main() {
    int x = 10;
    x %= 2;
    printf("The value of modulo operation: %d\n", x); 
 }


Output:



  The value of modulo operation: 0







More topic in C

Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send