From the course: Complete Guide to C Programming Foundations

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Using assignment operators

Using assignment operators

- [Instructor] In C programming, a variable can be modified by itself. The format for self-modifying a variable is shown in this code. Variable a is declared and initialized to 25 at Line 5. Line 8 adds 5 to the value of variable a, Line 10 removes 5 from variable a, Line 12 multiplies the value of variable a by 5, and then Line 14 divides the value of variable a by 5. These expressions work because, in C, the right side of the expression is evaluated first. The answer then slides over through the equal sign into the variable on the left. But there's a shortcut. I'll modify the code to use assignment operators. So a is increased by 5. And a is decreased by 5. A is multiplied by 5. And a is divided by 5. The output is the same. Here are the C language assignment operators. Each allows you to self-modify a variable by the arithmetic operator shown. The secret to remembering the order is that the equal sign goes last. For example, this expression subtracts 5 from the value of variable a,…

Contents