? Operator in DM - Practical Electron Microscopy and Database - - An Online Book - |
||||||||||||||
Microanalysis | EM Book http://www.globalsino.com/EM/ | ||||||||||||||
================================================================================= | ||||||||||||||
One of the most fascinating operators in C++ is the ?. The ? here is called a ternary operator because it requires three operands. The ? operator can be used to replace if-else statements as shown in Table 1118a. Table 1118a. Comparison of applications between ? operator and if-else statements.
In the arithmetic mask form "xyz1 ? xyz2 : xyz3" in the example, xyz1 is always evaluated. If xyz1 evaluates to true (not 0) xyz2 is evaluated and its result used as the value of the whole expression. Otherwise, xyz3 is evaluated and its result used as the value of the whole expression. Table 1118b. More examples of applications of the ? operator.
|
||||||||||||||
================================================================================= | ||||||||||||||
|
||||||||||||||