Download docx - c Interview

Transcript

How to write a running C code without main()?

1. Using a macro

#include#define extra mainint extra(void){printf("freakyfresher");return 0;}

Output:freakyfresher

2. Using Token-Pasting Operator

If we are not allowed to even write main, we can use token-pasting operator(## basically for concatenation)

#include#define extra m##a##i##nint extra(){printf("freakyfresher");return 0;}

Output:freakyfresher

How can we sum the digits of a given number in single statement?

int sumDigits(int no){return no == 0 ? 0 : no%10 + sumDigits(no/10) ;}

int main(void){printf("%d", sumDigits(132));getchar();return 0;}

Print 1 to 1000 with out loop and conditionals

#includestatic int current = 1;struct print{print() { std::cout