Click to See Complete Forum and Search --> : one C question please.. :-)
mahanare
June 7th, 2004, 12:18 PM
HI.
Pl solve this quiz .... and reply back plz!!
if(X)
{
printf("Hello");
}
else
{
printf("World");
}
Question: What should be the value of "X" so that the output is HelloWorld
Bond
June 7th, 2004, 12:40 PM
It will only print one or the other. It's in an if/else statement.
Unless X is:
printf("Hello") && false
or:
!printf("Hello")
mahanare
June 8th, 2004, 12:26 AM
Thanx, Bond
Bond
June 8th, 2004, 11:03 AM
Was this for a class or something?
mahanare
June 9th, 2004, 01:51 AM
no one of my friend asked this problem to me..
here is one more solution
#include <stdio.h>
#define X a==0?a++,main():1
int main()
{
static int a=0;
if(X)
{
printf("Hello");
}
else
{
printf("World");
}
return 0;
}
Bond
June 9th, 2004, 11:38 AM
Interesting. I've never called main from within main before.
MrViggy
June 9th, 2004, 11:52 AM
Actually, I'm not sure that's valid (to recursively call main).
Ahh, yes, in this thread I saw that:
http://www.codeguru.com/forum/showthread.php?s=&threadid=295571
In C, you can recursively call main, however that is illegal in C++.
Viggy
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.