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 - C Tutorial
From the course: Complete Guide to C Programming Foundations
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
-
-
-
-
-
Working with math operators3m 13s
-
(Locked)
Challenge: Do some math50s
-
(Locked)
Solution: Do some math1m 47s
-
(Locked)
Using assignment operators1m 49s
-
(Locked)
Obeying the order of precedence3m 14s
-
(Locked)
Challenge: Get the order correct55s
-
(Locked)
Solution: Get the order correct1m 37s
-
(Locked)
Working with relational operators3m 48s
-
(Locked)
Using logical operators3m 58s
-
(Locked)
Understanding bitwise operators3m 44s
-
(Locked)
Shifting bits3m 13s
-
(Locked)
Exploring unary operators3m 3s
-
Chapter challenge: More math1m 8s
-
(Locked)
Chapter solution: More math2m 45s
-
-
-
-
-
-
-
-
-