<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vincent Gable's Blog &#187; Pointers</title>
	<atom:link href="http://vgable.com/blog/tag/pointers/feed/" rel="self" type="application/rss+xml" />
	<link>http://vgable.com/blog</link>
	<description>my weblog.</description>
	<lastBuildDate>Tue, 29 Nov 2011 22:20:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>A C &amp;Puzzler[]</title>
		<link>http://vgable.com/blog/2009/12/25/a-c-puzzler/</link>
		<comments>http://vgable.com/blog/2009/12/25/a-c-puzzler/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 20:35:54 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[Bug Bite]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Arrays]]></category>
		<category><![CDATA[GCC]]></category>
		<category><![CDATA[Pointers]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/?p=547</guid>
		<description><![CDATA[Here&#8217;s a C-puzzler for you! given this function, void foo(char* s){ printf("s is at: %p\n s is: '%s'\n", s, s); } and that char s[] = "Joy!"; foo(s); prints out s is at: 0xbffff46b s is: &#8216;Joy!&#8217; what will this next line print? foo(&#038;s); //WHAT WILL THIS DO? Pick all that apply: Print &#8220;Joy!&#8221; Print [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a C-puzzler for you!</p>
<p>given this function,</p>
<pre>void foo(char* s){
	printf("s is at: %p\n s is: '%s'\n", s, s);
}</pre>
<p>and that</p>
<pre>
char s[] = "Joy!";
foo(s);
</pre>
<p>prints out</p>
<blockquote><p>
s is at: <code>0xbffff46b</code><br />
s is: &#8216;Joy!&#8217;
</p></blockquote>
<p>what will this next line print?</p>
<pre><strong>foo(&#038;s); //WHAT WILL THIS DO?</strong>
</pre>
<p>Pick all that apply:</p>
<ol>
<li>Print &#8220;Joy!&#8221;</li>
<li>Print garbage</li>
<li>Print the same address for <code>s</code></li>
<li>Print the a different address for <code>s</code></li>
<li>Crash</li>
<li>Go into an Infinite loop</li>
</ol>
<h3>Answer</h3>
<p><small>Answer: one and three</small></p>
<p>Yeah, it&#8217;s not what I expected either, especially since:</p>
<pre>@encode(__typeof__(s)) = [5c]
@encode(__typeof__(&#038;s)) = ^[5c]</pre>
<p>In fact, all of these are equvalent (modulo type warnings):</p>
<pre>
foo(s);
foo(&#038;s[0]);
foo(&#038;(*s));
foo(&#038;s);
</pre>
<p><a href="http://www.reddit.com/r/programming/comments/i6k5/jeez_after_all_these_years_a_c_array_vs_pointer">Explanation</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2009/12/25/a-c-puzzler/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

