C Programming - Print In Reverse-Order
This is only for printing, we are not storing the reversed output anywhere and another shortcoming is that it will cause SEGFAULT for a huge length string.Recursive main() calling!! For beginners it will be a great to surprise to call main() function within main() it, but wait, Isn't main() also a function?
/* reverse.c */
#include
int main()
{
char ch;
if ( (ch=getchar()) != '\n' ) {
main();
printf("%c",ch);
}
}/* EOF */
Is it necessary to have a main() function for success full compilation (there is no function main() written anywhere in any of our translation unit)
No, We can write a variable named main, and that is enough for the compilation phase to succeed.
/* withoutmain.c */
int main;
/* EOF */
Labels: C
About this entry
You’re currently reading “
- Published:
- 3:58 am
- by -
0 Comments (Post a Comment)