• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Another Puzzle

 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int x=0;
int y=1;

System.out.println(x-y);
System.out.println(x/y);

- Manish
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
x++, y--
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sameer Jamal
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic