Write a C code that prints “Hello C” without any main function. This is a trick question and can be solved in following ways.
1) Using a macro that defines main
#include<stdio.h>#define fun mainint fun(void){ printf("Hello C"); return 0;} |
Output:
Hello C
2) Using Token-Pasting Operator
The above solution has word ‘main’ in it. If we are not allowed to even write main, we ca use token-pasting operator (see this for details)
The above solution has word ‘main’ in it. If we are not allowed to even write main, we ca use token-pasting operator (see this for details)
#include<stdio.h>#define fun m##a##i##nint fun(){ printf("Hello C"); return 0;} |
Output:
Hello C
No comments:
Post a Comment