Consider the below C/C++ program.
What would the output of the above program – ‘5’ or ’10’?
The output is undefined as the order of evaluation of f1() + f2() is not mandated by standard. The compiler is free to first call either f1() or f2(). Only when equal level precedence operators appear in an expression, the associativity comes into picture. For example, f1() + f2() + f3() will be considered as (f1() + f2()) + f3(). But among first pair, which function (the operand) evaluated first is not defined by the standard.
Thanks to Venki for suggesting the solution.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Order of operands for logical operators
- What is evaluation order of function parameters in C?
- Operands for sizeof operator
- Sorting 2D Vector in C++ | Set 2 (In descending order by row and column)
- Sorting Vector of Pairs in C++ | Set 2 (Sort in descending order by first and second)
- How to Read and Print an Integer value in C
- Nested switch case
- Inline function in C
- Find the Nth term of the series 14, 28, 20, 40,.....
- Loader in C/C++
- Sum of array Elements without using loops and recursion
- Program to Convert Hexadecimal to Octal
- Is there any equivalent to typedef of C/C++ in Java ?
- Find amount to be added to achieve target ratio in a given mixture