Operators / Residual Values
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
Now you know the expressions usually result in a single value. This expression combines the two variables A and B and results in the arithmetic sum of the two being stored in X. The Rvalues of A and B are used but left unchanged. It's possible to write expressions that have a side effect of modifying the Rvalues of the variables it uses. This expression first adds A and B, then stores the result in A. The plus equal operator has a residual value, the sum of the two numbers. It is this residual value that is taken to be the Rvalue of the expression and assigned to X. You can use this type of operation in a number of ways. This expression assigns two to D, then the residual value of that assignment is used as an Rvalue and is assigned to C. That residual value is assigned to B, then to A and finally to X. This is the way this feature normally is used to initialize a group of variables to a single value. You can use any of the assignment operators in the same way. This works from right to left. First D is set to five. Then C, which is 20, is divided by five so C is then set to four, which is added to B, which is six. So B is set to 10. The 10 is multiplied by A, which is three, so it becomes 30. That is the value assigned to X. So in this example, the value of every variable is changed but they're all changed in a different way. This capability is simply a consequence of the capabilities of C and how the Rvalues and Lvalues are handled by the compiler. But there is another not-so-common capability that was intentionally included in the language. In this expression, A is a conditional expression. If it is true, the residual value is the Rvalue of B. Otherwise, it's the Rvalue of C. It works like this. First the expression A is evaluated. If the result is not zero, expression B is evaluated and the result is taken to be the Rvalue. If the result from expression A is zero, expression C is evaluated and the result becomes its Rvalue. It may be important to remember that A is always evaluated and only one of the expressions, B or C, is evaluated. So watch those side effects. By the way, there is a synchronization point immediately following the expression A so you can safely use the result from it in B or C. Expressions using this type of conditional usually look something like this. But it's perfectly valid to nest them one inside the other. This is a completely valid expression but it may be a little hard to read. The compiler won't get confused but you might. If you do something like this, I would suggest that you use parenthesis just so things look a little clearer.
Tutorial Information
| Course: | Advanced C Programming |
| Author: | Arthur Griffith |
| SKU: | 33965 |
| ISBN: | 1-935320-24-6 |
| Release Date: | 2009-01-30 |
| Duration: | 5.5 hrs / 82 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 