Consider the below 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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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)
- Program to copy the contents of one array into another in the reverse order
- Strict Aliasing Rule in C with Examples
- Difference between C and Dart
- Difference between Sentinel and Counter Controlled Loop in C
- Why do we need reference variables if we have pointers
- What are the differences between C and Embedded C?
- Macros and its types in C/C++
- Draw a smiley face using Graphics in C language
- NULL undeclared error in C/C++ and how to resolve it