[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]



What's strange about it. [ is a commutative operator, so a[i] and i[a]
represent the same thing i.e. *(a+i). The reason the compiler doesn't complain
is that printf takes a void pointer in that spot, so since the result is a
char *, no worries.

BAJ
> 
> 	bjorn
> 
> --------------------------------------------------
> 
> /* Find the strangeness! Spotted on kuro5hin... */
> #include <stdio.h>
> 
> char *foo[] = {"what", "the", "heck", "is", "this"};
> 
> int main(int argc, char **argv)
> {
>   int j=2;
>   printf("Test: %s\n", j[foo]);
>   return 0;
> }
> _______________________________________________
> Ale mailing list
> Ale at ale.org
&gt; <a  rel="nofollow" href="http://www.ale.org/mailman/listinfo/ale";>http://www.ale.org/mailman/listinfo/ale</a>


</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<ul><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><a name="00437" href="msg00437.html">[ale] This is legal C:</a></strong>
<ul><li><em>From:</em> bjorn at sccs.swarthmore.edu (Bjorn Dittmer-Roche)</li></ul></li>
</ul></li></ul>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00434" href="msg00434.html">[ale] This is legal C:</a></strong>
<ul><li><em>From:</em> bjorn at sccs.swarthmore.edu (Bjorn Dittmer-Roche)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00435.html">[ale] This is legal C:</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00437.html">[ale] This is legal C:</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00435.html">[ale] This is legal C:</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00437.html">[ale] This is legal C:</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00436"><strong>Date</strong></a></li>
<li><a href="threads.html#00436"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>