The question is:
Yesterday my friend had taken interview in Microsft.If u know this
Plz answer this
main() // line 1
{
printf("TWO");
} //line4
U don't change from line1 to line4. u will add anything before the
main function only.
write the solution with 10 ways.
We want the ouput is->
One
Two //注意,不是TWO!
Three
There are several ways to solve the question, the following is:
First:to ignore the main funcion
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("One\nTwo\nThree\n");
return 0;
}
#define main XXX
main() // line 1
{
printf("TWO");
} //line4
The second way:To ignore the printf function
int xxx(const char* x)
{
return printf("One\nTwo\nThree\n");
}
#define printf xxx
main() // line 1
{
printf("TWO");
} //line4
The last way: using struct
#include <stdio.h>
struct Foo
{
Foo(){printf("One\nTwo\nThree\n");exit(0);}
}foo;
main() // line 1
{
printf("TWO");
} //line4