Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!ginosko!uunet!mcsun!sunic!tut!hydra!hylka!teittinen
From: TEITTINEN@cc.helsinki.fi
Newsgroups: comp.lang.c
Subject: "abcdef"[3] == 3["abcdef"], but why?
Message-ID: <781@cc.helsinki.fi>
Date: 29 Sep 89 15:29:00 GMT
Lines: 19


As I was trying to figure out what the cryptic maze program (posted to
net some days ago) does, I ran into a very interesting feature of C. The
program exploiting the fact that the following equation is true

         "abcdef"[3] == 3["abcdef"]   (both equal to 'd')

In fact, not only the values are the same. If the string "abcdef" was
replaced by a pointer to char, the expressions would refer to the same
memory location! This can't be a compiler-dependent feature (or bug)
because the maze program runs correctly on various machines.

Could someone explain to me what a C compiler does when it runs into
expression 3["abcdef"]? 

-- 
EARN: teittinen@finuh                        ! "Studying is the only way
Internet: teittinen@cc.helsinki.fi           !  to do nothing without
Marko Teittinen, student of computer science !  anyone blaming you" -me