The code is::::: if(condition)
Printf("Hello");
Else
Printf("World");
What will be the condition in if in such a way that both
Hello and world are printed in a single attempt?????? Single
Attempt in the sense... It must first print "Hello" and it
Must go to else part and print "World"..... No loops,
Recursion are allowed........................

Answer Posted / fazil

/* Solution 1: */

int main(int argc, char* argv[])
{
if( argc == 2 || main( 2, NULL ) )
{
printf("Hello ");
}
else
{
printf("World\n");
}
return 0;
}

/* Solution 2 (Only for Unix and Linux): */

int main(int argc, char* argv[])
{
if( !fork() )
{
printf("Hello ");
}
else
{
printf("World\n");
}
return 0;
}

Is This Answer Correct ?    4 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is static and volatile in c?

1016


What is fflush() function?

906


When should you not use a type cast?

908


Explain the difference between null pointer and void pointer.

878


What is an auto keyword in c?

889


Explain how do you generate random numbers in c?

847


What is the difference between ++a and a++?

977


What is uint8 in c?

912


What are the features of the c language?

875


There seem to be a few missing operators ..

837


What is a pointer in c?

1038


What is the use of typedef in structure in c?

742


Explain what is the use of a semicolon (;) at the end of every program statement?

995


p*=(++q)++*--p when p=q=1 while(q<=6)

1518


Is it fine to write void main () or main () in c?

774