What does Z["ack"] = 5 mean?

George Kyriazis kyriazis at rpics
Thu Oct 6 06:54:02 AEST 1988


In article <14999 at agate.BERKELEY.EDU> laba-3aw at web.berkeley.edu (Sam Shen) writes:
>Exactly what does this mean:
>
>main()
>{
>	char Z;
>
>	Z["ack!"] = 5;
>}
>

	Something like that was posted a few months ago.  Remember that

		a[b]  == *(a+b)		[pointer erithmetic]
		*(a+b) == *(b+a)	[obvious]
		*(b+a) == b[a]		[!!!!]

	In other words  Z["ack!"] == "ack!"[Z]  (!!). Z happens to be '\0',
so what is does is changes the first character of the constant "ack!" to 5.
In some systems you can't do that because constants are read-only.  I just
tried it on a SUN4 and it didn't complain at all..

  George Kyriazis
  kyriazis at turing.cs.rpi.edu
------------------------------



More information about the Comp.lang.c mailing list