| Author |
Another Puzzle
|
Sameer Jamal
Ranch Hand
Joined: Feb 16, 2001
Posts: 1870
|
|
Suppose x and y are distinct identifiers of type integer. show a simple context into which either of the code fragments x = 0; y = 1 or y = 1; x= 0 can be substituted so that in most programming languages the resulting substitutions yield different results. [ February 22, 2006: Message edited by: Sameer Jamal ]
|
 |
Manish Hatwalne
Ranch Hand
Joined: Sep 22, 2001
Posts: 2573
|
|
int x=0; int y=1; System.out.println(x-y); System.out.println(x/y); - Manish
|
 |
Vishnu Prakash
Ranch Hand
Joined: Nov 15, 2004
Posts: 1026
|
|
|
x++, y--
|
Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
Sameer, is the ':' intentional in "x:= 0"? If so, is it intentional that all 3 other expressions do not include a ':'? I'm thinking maybe the solution is in a for loop, where is different in effect from However we need to distinguish between = and == to get this to compile. Most other languages nowadays distinguish between relational operators and assignments - seeing := makes me think of Pascal for example. I don't see a good way to make your text work for any language I'm currently familiar with. Can you confirm the exact syntax, and maybe give a specific languuage it definitely works in?
|
"I'm not back." - Bill Harding, Twister
|
 |
Sameer Jamal
Ranch Hand
Joined: Feb 16, 2001
Posts: 1870
|
|
Originally posted by Jim Yingst: Sameer, is the ':' intentional in "x:= 0"? If so, is it intentional that all 3 other expressions do not include a ':'?
No it was not intentional it was just a typing mistake. There are few languages where comparison operator '==' will not work for eg: VB 6.0 The context can be In the case that the first code fragment is substituted for the ellipsis, the effect is to set z to 1, while in the second case z gets set to 0. [ February 22, 2006: Message edited by: Sameer Jamal ]
|
 |
 |
|
|
subject: Another Puzzle
|
|
|