A trick with if-else

K

Kenneth Brody

Suman said:
Vladimir said:
Suman said:
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: <mailto:[email protected]>
 
K

Kenneth Brody

Vladimir said:
Chris said:
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: <mailto:[email protected]>
 
V

Vladimir Oka

Kenneth Brody opined:
Vladimir said:
Chris said:
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.)
 
P

pete

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
 
C

Chris Dollin

Vladimir said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,517
Latest member
Andres38A1

Latest Threads

Top