Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > A trick with if-else

Reply
Thread Tools

A trick with if-else

 
 
Kenneth Brody
Guest
Posts: n/a
 
      05-16-2006
Suman wrote:
>
> Vladimir Oka wrote:
> > Suman wrote:
> > > Vladimir Oka wrote:
> > > > Piyush Agarwal wrote:
> > >
> > > [ snip code with UB ]
> > >
> > > > > What value can be given to x such that the output is "Hello
> > > > > World"?
> > > >
> > > > I think you misrepresented the trick question.
> > > >
> > > > With `x` an `int` it will never work.
> > >

[... snip code with rewritten main() ...]
> >
> > I don't think you were allowed to change the `if` statement. Have a
> > look at my other post as well.

>
> Show me where this constraint was mentioned


The original post said:

What value can be given to x such that the output is "Hello World"?

All you're allowed to do is give x a value.

If you're allowed to modify the code, why not just:

#include <stdio.h>
int main(void)
{
printf("Hello World\n");
}

[...]

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <(E-Mail Removed)>


 
Reply With Quote
 
 
 
 
Kenneth Brody
Guest
Posts: n/a
 
      05-16-2006
Vladimir Oka wrote:
>
> Chris Dollin wrote:
> > Vladimir Oka wrote:
> >
> > > Chris Dollin wrote:
> > >> S'not portable - there's no final newline after the World.
> > >>
> > >> int x = (printf( "Hello, World\n" ), exit( 0 ), 17);
> > >>
> > >> will do fine.
> > >
> > > Yep. Using 42 instead of 17 would have been even better.

> >
> > No, it wouldn't - I didn't wish to allude to tHGttG. Instead I alluded
> > to something else.

>
> You got me there. I dont get the allusion.
>
> [17 *is*, more often than not, my staple "random" value, but I doubt
> you know me that well. ]


But everyone knows that 17 is the "least random" number. Use 37 instead.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <(E-Mail Removed)>

 
Reply With Quote
 
 
 
 
Vladimir Oka
Guest
Posts: n/a
 
      05-16-2006
Kenneth Brody opined:

> Vladimir Oka wrote:
>>
>> Chris Dollin wrote:
>> > Vladimir Oka wrote:
>> >
>> > > Chris Dollin wrote:
>> > >> S'not portable - there's no final newline after the World.
>> > >>
>> > >> int x = (printf( "Hello, World\n" ), exit( 0 ), 17);
>> > >>
>> > >> will do fine.
>> > >
>> > > Yep. Using 42 instead of 17 would have been even better.
>> >
>> > No, it wouldn't - I didn't wish to allude to tHGttG. Instead I
>> > alluded to something else.

>>
>> You got me there. I dont get the allusion.
>>
>> [17 *is*, more often than not, my staple "random" value, but I doubt
>> you know me that well. ]

>
> But everyone knows that 17 is the "least random" number. Use 37
> instead.


Well, occasionally I use 57 instead.

(Probably has something to do with how it sounds in my native language.
Interestingly, although I fully think in English when I use it, I
still always think numbers in my native language. I don't understand
it, really.)

--
Killing is stupid; useless!
-- McCoy, "A Private Little War", stardate 4211.8

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      05-16-2006
Vladimir Oka wrote:

> Well, occasionally I use 57 instead.
>
> (Probably has something to do with how it sounds in
> my native language.
> Interestingly, although I fully think in English when I use it, I
> still always think numbers in my native language. I don't understand
> it, really.)


Results 1 - 10 of about 76 for "57 card carrying communists".

Results 1 - 10 of about 176,000 for "57 varieties".

http://www.snopes.com/business/hidden/heinz57.asp

--
pete
 
Reply With Quote
 
Chris Dollin
Guest
Posts: n/a
 
      05-17-2006
Vladimir Oka wrote:
> Chris Dollin wrote:
>> Vladimir Oka wrote:
>>
>> > Chris Dollin wrote:
>> >> S'not portable - there's no final newline after the World.
>> >>
>> >> int x = (printf( "Hello, World\n" ), exit( 0 ), 17);
>> >>
>> >> will do fine.
>> >
>> > Yep. Using 42 instead of 17 would have been even better.

>>
>> No, it wouldn't - I didn't wish to allude to tHGttG. Instead I alluded
>> to something else.

>
> You got me there. I dont get the allusion.


There was of course a clue in my signature. Don't worry - the allusion is
obscure; I just wanted a change.

--
Chris "anyway, I don't paint." Dollin
"Everyone generalises from a single example. I know I do." - Vlad Taltos
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
profile trick, really anoying Splibbilla Firefox 2 06-29-2005 08:39 PM
so... what's the trick in getting wireless working on Server 2003?! pif Wireless Networking 1 10-13-2004 04:21 PM
A .Net trick everday! Nuri YILMAZ ASP .Net 0 08-09-2004 07:58 AM
A .Net trick everyday! Nuri Yilmaz ASP .Net 0 07-28-2004 01:46 PM
Is this trick with reset acceptable? valentin tihomirov VHDL 6 04-14-2004 05:52 PM



Advertisments