Operators in C Language | Part-2

Assignment operator

  1. = operator is called assignment operator.
  2. It is used to move the value or expression result in a variable.
  3. Assignment operator are evaluated from right to left order.

Example of assignment:

  1. a = b = 5, In this example the 5 is assignment in b then b's value is moved to a.
  2. a = b + 5, Assignment operator have the lowest precedence so all other operator are evaluated first and then result is moved to the variable.
  3. 5 = a, This is an error, because in this example we are trying to move the value of variable into constant and constant can't be changed.The same error will be prompted if you are try the expression 6 + b = a.

Compound assignment

+=, -=, *=, /=, %= are called compound assignment operator. It combine the Arithmetic as well as assignment simultaneously.
Compound Assignment Equivalent Expression
a += 5 a = a + 5
a -= 5 a = a - 5
a *= 5 a = a * 5
a /= 5 a = a / 5
a %= 5 a = a % 5
Previous Back to C Programming index Next

Comments

Popular posts from this blog

String in golang

Inline V/S Block Level Element

Floating point Data types in Go lang

Escape Sequence | Formatted Printing | Interview Questions

Sum of two numbers

Operators in C Language| Part-4

Printing in C programming

Arrays in C Language

Program to check a year is leap year or not.

Data types in Java