Solution for Exercise 4.33 of C++ Primer 5th Edition.
2014-10-28 21:01
316 查看
Explain the following expression: someValue ? ++x, ++y : --x, --y;
I was stuck by this expression for some time, and now I figure it out. Please allow me to share my process of thinking.
Frist, we know that the precedence of comma operator "," is the lowest. So the expression equals to (someValue ? ++x, ++y : --x), --y; Besides, we must be aware of that the associality of ?: operator is from right to left.
Then, when somevalue is false, then we should get the value from the right of sub expression: --x, --y; Then the value value should be --y.
For true condition, the result of the left sub expression is ++y. However, we must note that there is still a --y in the end following a comma, then the final value for y should minus 1 from the ++y expression. Hence, acutally, when true, the result is y itself after a addition and a subtraction.
In a word, this expression is equivalent to somevalue ? y : --y;
If there is any mistakes in my thinking, please let me know, thanks for reading.
相关文章推荐
- 《C++ Primer (5th Edition)》笔记-Part III . Tools For Class Authors
- Solution for Introduction to Algorithms (3rd Edition) Exercise 26.4-2
- Exercise for Chapter 7 of "Intermediate Perl"
- 《C++ Primer (5th Edition)》笔记-Part II . The C++ Library
- 读书笔记:C++ primer 5th edition--chapter18.用于大型程序的工具
- SQL For Dummies®, 5th Edition
- C++ Primer 中文版 5th Edition 练习15.8和练习15.9的解答
- solution for solving OutOfMemoryError: Java heap space
- Solution for exercise 1.2-1 in Introduction to Algorithms
- Solution for Exercise 15.1-2 of CLRS
- Solution for error "Store update, insert, or delete statement affected an unexpected number of rows" .
- C++ primer 5th edition:7.1.2节(关于this指针;关于const member functions)
- Solution for Store update, insert, or delete statement affected an unexpected number of rows (0)
- 读书笔记:C++ primer 5th edition--chapter11.关联容器
- Solution for exercise 1.2-3 in Introduction to Algorithms
- 读书笔记:C++ primer 5th edition--chapter16.模板与泛型编程
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- (转)A drop-in universal solution for moving text fields out of the way of the keyboard
- 《C++ Primer 5th edition》 第一章 开始
- 读书笔记:C++ primer 5th edition--chapter14.重载运算与类型转换