TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

C Puzzles

101 pointsby brown-dragonalmost 10 years ago

5 comments

JoshTriplettalmost 10 years ago
&gt; Write a C program which prints Hello World! without using a semicolon<p>Here&#x27;s one way, cheating a bit by abusing the definition of &quot;a C program which prints&quot;:<p><pre><code> &#x2F;tmp$ gcc hw.c hw.c:1:2: warning: #warning Hello world! [-Wcpp] #warning Hello world! </code></pre> A more serious solution, though:<p><pre><code> &#x2F;tmp$ cat hw.c #include &lt;stdio.h&gt; void main(void) { if (puts(&quot;Hello world!&quot;)) {} } &#x2F;tmp$ gcc hw.c &#x2F;tmp$ .&#x2F;a.out Hello world!</code></pre>
评论 #9762766 未加载
FreeFullalmost 10 years ago
<p><pre><code> #include &lt;stdio.h&gt; int main() { float a = 12.5; printf(&quot;%d\n&quot;, a); printf(&quot;%d\n&quot;, *(int *)&amp;a); return 0; } </code></pre> This program invokes undefined behaviour when it casts float\* to int\*, so technically it could print anything, or do something else. I&#x27;m not sure how using memcpy instead would impact the puzzle&#x27;s point though.
评论 #9764570 未加载
评论 #9764134 未加载
评论 #9764801 未加载
评论 #9764475 未加载
nathellalmost 10 years ago
One of these reminded me of my woeful attempts at IOCCC-like code, a Hello World implementation:<p><a href="http:&#x2F;&#x2F;students.mimuw.edu.pl&#x2F;~dj189395&#x2F;nhp&#x2F;czynic&#x2F;programy&#x2F;tidbits&#x2F;guess.c" rel="nofollow">http:&#x2F;&#x2F;students.mimuw.edu.pl&#x2F;~dj189395&#x2F;nhp&#x2F;czynic&#x2F;programy&#x2F;t...</a>
评论 #9762517 未加载
kazinatoralmost 10 years ago
Anyone else spot the uninitialized variable in the banner program?<p>Also:<p>&gt; <i>What&#x27;s the output of the following program. (No, it&#x27;s not 10!!!) </i><p>What&#x27;s the point of including a program that calls malloc without including a prototype for it, after asking the reader earlier answer why such a program segfaults on IA-64 but not IA-32?<p>(The answer is: a constraint is violated, requiring a diagnostic, because an int * object pointer is assigned the return value of malloc whose implicit declaration marks it as returning int. The comment issue is a red herring.)
评论 #9762778 未加载
评论 #9762927 未加载
rooneyyyyalmost 10 years ago
I couldn&#x27;t find the book at the hint provided... Could someone help me get that book. Thanks in advance
评论 #9764992 未加载