Assignment operators

Assignment operators

Assignment operator in C language is used to assign a value to a variable declared in the program. Assignment operator is mainly used to store the result of a program expression or value in a variable.

Assignment operators

So let’s know the assignment operator in C language.

Assignment (=) operator.

Example.

int p;

p = 1; //Variable p is assigned the value 1

Addition assignment (+=) operator.

Adds the value of the right operand to the left operand of an existing C program, and assigns the result to the left operand.

Addition assignment (+=) operator.

Example.

int p = 1;

p += 3; // Equivalent to p = p + p; => a becomes 4

Subtraction assignment (-=) operator in C.

Subtracts the value of the right program operand from the value of the left operand in the current C program, and assigns the current program output result to the left operand.

Subtraction assignment (-=) operator in C.

int p = 7;

p -= 2; // Equivalent to p = p – 2; => p becomes 5

Multiplication assignment (*=) operator in C.

Multiplies the value of the left program operand by the value of the right operand in the C language, and assigns the program output result to the left operand.

Multiplication assignment (*=) operator in C.

int p = 4;

p *= 2; // Equivalent to p = p * 2; => p becomes 8

Division assignment (/=) operator in C.

The current C program declares a variable that divides the value of the left operand by the value of the right operand and assigns the program output result to the left operand.

Division assignment (/=) operator Example.

int p = 8;

p /= 2; // Equals p = p / 2; => p becomes 4

Modulus assignment (%=) operator in C.

The current C program calculates the modulus by dividing the value of the left operand by the value of the right operand and assigns the program output result to the left operand.

Modulus assignment (%=) operator Example.

int p = 10;

p %= 3; // Equals p = p % 3; => p becomes 1

Assignment operator.

Assignment operators in C language are used to modify the value of program variables based on mathematical program operations.

Assignment operators are a method of combining mathematical operations with assignment.

Assignment operators in C programming can be used with variables of any data type.