My Profile

Keep Up to Date:
Blog RSS
Blog
Forum RSS
Forum
Search

Buy & Sell

Used (Like New) $20

Post New Topic Post Reply
Posted 1 Year, 1 Month ago
paydayuscf
Senior Boarder
Posts: 79
graphgraph
User Offline
 
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.
Posted 1 Year, 1 Month ago
Atraxani
Senior Boarder
Posts: 78
graphgraph
User Offline
 
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.
Posted 1 Year, 1 Month ago
davidm
Senior Boarder
Posts: 65
graphgraph
User Offline
 
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.
Posted 1 Year, 1 Month ago
Via Caltha
Expert Boarder
Posts: 85
graphgraph
User Offline
 
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.
Posted 1 Year, 1 Month ago
Lindy
Senior Boarder
Posts: 74
graphgraph
User Offline
 
The result is undefined and therefore implementation-dependant. As is the result of your other program.
The administrator has disabled public write access.
 
Copyright © 2006 - Jan 2009 Fun Quizzes Club