All Questions

671
votes
13answers
54348 views

Why are these constructs (using ++) undefined behavior in C?

#include <stdio.h> int main(void) { int i = 0; i = i++ + ++i; printf("%d\n", i); // 3 i = 1; i = (i++); printf("%d\n", i); // 2 Should be 1, no ? volatile int u = 0; u...
75
votes
7answers
13758 views

What are the rules for evaluation order in Java?

I am reading some Java text and got the following code: int[] a = {4,4}; int b = 1; a[b] = b = 0; In the text, the author did not give a clear explanation and the effect of the last line is: a[1] =...
35
votes
6answers
10492 views

Operator Precedence vs Order of Evaluation

The terms 'operator precedence' and 'order of evaluation' are very commonly used terms in programming and extremely important for a programmer to know. And, as far as I understand them, the two concep...
51
votes
6answers
18729 views

Compilers and argument order of evaluation in C++

Okay, I'm aware that the standard dictates that a C++ implementation may choose in which order arguments of a function are evaluated, but are there any implementations that actually 'take advantage' o...
152
votes
12answers
143318 views

Post-increment and pre-increment within a 'for' loop produce same output

The following for loops produce identical results even though one uses post increment and the other pre-increment. Here is the code: for(i=0; i<5; i++) { printf("%d", i); } for(i=0; i<5; ...
35
votes
2answers
2608 views

What are the evaluation order guarantees introduced by C++17?

What are the implications of the voted in C++17 evaluation order guarantees (P0145R3) on typical C++ code? (edit: updated the link to the latest version, r3) What does it change about things like i...
12
votes
6answers
3537 views

order of evaluation of operands

In the expression a + b, is a guaranteed to be evaluated before b, or is the order of evaluation unspecified? I think it is the latter, but I struggle to find a definite answer in the standard. Since...
15
votes
2answers
2503 views

Multiple preincrement operations on a variable in C++(C ?)

Why does the following compile in C++? int phew = 53; ++++++++++phew ; The same code fails in C, why?
1
votes
1answers
4201 views

Output of multiple post and pre increments in one statement

I'm new to C language so plz sum1 help me out. A C code written int i=3; printf("%d",++i + ++i); Complier gvs O/P =9. How? Thanx in advance
9
votes
3answers
11982 views

Order of execution in constructor initialization list

Is order of execution in constructor initialization list determinable? I know that members order in a class is the order in which those members will be initialized but if I have scenario like this: c...

Previous Next