Bloggers Wanted
We're looking for people to help with the main blog. If you are consistent, knowledgeable and you're into it, please drop me a note.
|
|
|
|
|
paydayuscf
Senior Boarder
Posts: 79
|
|
What will the following program print?
int array[5] = {0, 1, 2, 3, 4}; main() { int x = 2; if (array[x++]
|
|
The administrator has disabled public write access. |
Atraxani
Senior Boarder
Posts: 78
|
|
It might print 'They are equal.' or 'They are not equal.', depending on the order of evaluation of array[x++]
|
|
The administrator has disabled public write access. |
davidm
Senior Boarder
Posts: 65
|
|
Actually, it's worse than that - it's undefined. In theory, the underlying machine could be half-way through incrementing x when it decides to process array[x], so you might get some sort of access violation.
And making the obvious correction, you get the same range of responses.
|
|
The administrator has disabled public write access. |
Via Caltha
Expert Boarder
Posts: 85
|
|
Indeed. My compiler warns of such.
Quite right. However by assuming the closing parenthesis just before the equality comparison, it compiles and the result of both programs (at least on my platform with my compiler) is that they both say not
|
|
The administrator has disabled public write access. |
Lindy
Senior Boarder
Posts: 74
|
|
The result is undefined and therefore implementation-dependant. As is the result of your other program.
|
|
The administrator has disabled public write access. |
|
|
|