Question:
Write a program with out using main() function?
Answer:
#include<stdio.h>
#define decode(s,t,u,m,p,e,d) m##s##u##t #define begin decode(a,n,i,m,a,t,e)
int begin() { printf(" hello "); }
Source: CoolInterview.com
Answered by: Gopal Prajapati | Date: 7/2/2008
| Contact Gopal Prajapati
That's a very clever way of doing it. But still the code includes main!! Which means there is no answer for this question. Or perhaps i should say there is no way you could write a code with no main function in it.
Source: CoolInterview.com
Answered by: Harish Shivaraj | Date: 8/9/2008
| Contact Harish Shivaraj
It is not possible without main function Source: CoolInterview.com
Answered by: raveendra | Date: 8/13/2008
| Contact raveendra
main is a system defined function in C and since the program execution in c begins from the opening brace of main function it is mandatory to have main function in c. Source: CoolInterview.com
Answered by: ameya | Date: 8/21/2008
| Contact ameya
#include <stdio.h> _start() { _exit(myFunction());
}
int myFunction() { printf("Hi I called without main "); }
-------------------------------------------------------------- But you have compile this file as below
gcc -nostartfiles foo.c Source: CoolInterview.com
Answered by: harsh bhardwaj | Date: 9/19/2008
| Contact harsh bhardwaj
#define main() START START { printf("hi"); return 0; getch(); } Source: CoolInterview.com
Answered by: vaibhav | Date: 10/8/2008
| Contact vaibhav
Actually i didn't tried the first answer.except first one nothing works.please check it out. Source: CoolInterview.com
Answered by: Suresh S L | Date: 5/10/2009
| Contact Suresh S L
Writing a program without using main(). ------------------------------ /** test_file.c **/ void func() { printf (" v2karade "); exit(0); } -----------------------------
$gcc -nostartfiles -e func test_file.c
This will execute the func() function as main().
Source: CoolInterview.com
Answered by: Vinay Karade | Date: 5/27/2009
| Contact Vinay Karade
The execution starts from the main so it is not possible to start execution without main function. the above programs are not useful Source: CoolInterview.com
Answered by: girija prasad duggaraju | Date: 8/11/2009
| Contact girija prasad duggaraju
#include
#define decode(s,t,u,m,p,e,d)m##s##u##t
#define begin decode(a,n,i,m,a,t,e)
int begin()
{
printf("HELLO")
} Source: CoolInterview.com
Answered by: vikas | Date: 9/15/2009
| Contact vikas
it is nt possible 2 write a program widout main function as d program execution strts and ends at main Source: CoolInterview.com
Answered by: astha patni | Date: 11/1/2009
| Contact astha patni
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|