| Deutsch English Français Italiano |
|
<else-20241116103316@ram.dialup.fu-berlin.de> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: else ladders practice
Date: 16 Nov 2024 09:42:49 GMT
Organization: Stefan Ram
Lines: 40
Expires: 1 Dec 2025 11:59:58 GMT
Message-ID: <else-20241116103316@ram.dialup.fu-berlin.de>
References: <3deb64c5b0ee344acd9fbaea1002baf7302c1e8f@i2pn2.org> <slrnvi746p.fkp.dan@djph.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 1HWzTin3VuRMDjCm4vo1eQIbooZxTEv3uAwHrniyST/uLK
Cancel-Lock: sha1:DHc0+dWCm/k4YKWwA95NuXEqEkQ= sha256:OFZ44FR0Vx/rTEk16sxGvP+NFafnNCsSJ22icJ3eGSU=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Bytes: 2634
Dan Purgert <dan@djph.net> wrote or quoted:
>if (n==0) { printf ("n: %u\n",n); n++;}
>if (n==1) { printf ("n: %u\n",n); n++;}
>if (n==2) { printf ("n: %u\n",n); n++;}
>if (n==3) { printf ("n: %u\n",n); n++;}
>if (n==4) { printf ("n: %u\n",n); n++;}
>printf ("all if completed, n=%u\n",n);
My bad if the following instruction structure's already been hashed
out in this thread, but I haven't been following the whole convo!
In my C 101 classes, after we've covered "if" and "else",
I always throw this program up on the screen and hit the newbies
with this curveball: "What's this bad boy going to spit out?".
Well, it's a blue moon when someone nails it. Most of them fall
for my little gotcha hook, line, and sinker.
#include <stdio.h>
const char * english( int const n )
{ const char * result;
if( n == 0 )result = "zero";
if( n == 1 )result = "one";
if( n == 2 )result = "two";
if( n == 3 )result = "three";
else result = "four";
return result; }
void print_english( int const n )
{ printf( "%s\n", english( n )); }
int main( void )
{ print_english( 0 );
print_english( 1 );
print_english( 2 );
print_english( 3 );
print_english( 4 ); }