- World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Our Services
Get 9,000 Interview Questions & Answers in an eBook.

Get it now !!
Send your Resume to 6000 Companies

Search Interview Questions

Question: Can you write a c program without using main function?

Answer: we can write the programme without main but it can't run becuase linking is from main().

Category C Basics Interview Questions & Answers - Exam Mode / Learning Mode
Rating (0.5) By 1011 users
Added on 12/19/2013
Views 10543
Rate it!
Question: Can you write a c program without using main function?

we can write the programme without main but it can't run becuase linking is from main(). Source:

Answered by: Ameen | Date: 12/20/2008 | Contact Ameen Contact Ameen

yes,we can write c program without using main. Source:

Answered by: c.karuppusamy | Date: 12/22/2008 | Contact c.karuppusamy Contact c.karuppusamy


Answered by: k.sangeetha | Date: 1/6/2009 | Contact k.sangeetha Contact k.sangeetha

yes, we can write a c program without using main function. but it'll not be executed as the execution starts from the main function only. Source:

Answered by: rashmi | Date: 1/16/2009 | Contact rashmi Contact rashmi

basically,i thought not to post uo solution here but i have seen the same query in many web sites and no proper solution is found
so IM posting here the solution for this tragedic question
1)its true,we can't write a C program without main function

#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 ?);
i listened people who said program will not get executed,DAMN stop such things.if you don't know plz shut your mouths and don't mislead readres plzzzzzzz
the above code works perfectly and if any1 need the explanation for that plz refer and in the right most side (below) see C SOURCE CODES coloumn and then read it there clearly.even after that if you have any doubts feel free to contact me at Source:

Answered by: venkat | Date: 7/6/2009 | Contact venkat Contact venkat

otherwise try this one...

void funtion_name()
printf("Without main

and compile this code like this..
$cc -nostartfile source_file.c Source:

Answered by: Rao Sahab | Date: 9/20/2009 | Contact Rao Sahab Contact Rao Sahab

yeah ofcourse we can write a c prog without using main().,. but it leads to error in it's execution stage Source:

Answered by: lol | Date: 11/12/2009 | Contact lol Contact lol

a program cannot be executed witout a main()function.Since te compiler starts compiling te program after te main() Source:

Answered by: sukanya | Date: 12/8/2009 | Contact sukanya Contact sukanya

we can write the code without main() function. The code will gets compiled and during compilation it won't show any error but while executing it show an error saying LINKER ERROR. Source:

Answered by: deepak | Date: 12/15/2009 | Contact deepak Contact deepak

Yes we can write a C Program without writing main()

see this

#pragma start show()

void show()

Answered by: Swesh Mishra | Date: 1/7/2010 | Contact Swesh Mishra Contact Swesh Mishra

yes you can write a program without main but in short just like this

printf("stupids we can do anything");
} Source:

Answered by: sanjana | Date: 3/6/2010 | Contact sanjana Contact sanjana

yes we can write c prog without using main() but it will not run because the prog execution always begins with the main() function.
so it will give an error. Source:

Answered by: abhinav kumar singh | Date: 3/7/2010 | Contact abhinav kumar singh Contact abhinav kumar singh

The compilation process always starts from the first line of your source code and the compiler checks only syntax, if you don't have a main() not at all a problem. But if you want to execute that you need main(). Check how we are going to create a header file are we going to place a main() in a header file. Source:

Answered by: venkatesh | Date: 3/21/2010 | Contact venkatesh Contact venkatesh

No we conn't write c program with out using main().Because it shows error in its run time. Source:

Answered by: Latthi.k | Date: 4/3/2010 | Contact Latthi.k Contact Latthi.k


#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(? without main ?);
} Source:

Answered by: naresh | Date: 4/13/2010 | Contact naresh Contact naresh

main is not compulsory, every C program needs an entry point so it can be main, pain, slain or anything else, in embedded systems the low level startup code jumps to main, u can change it to something else, similar in visual studio or turbo C u need to find out a compile directive to change the default jump to main.
and to correct the above answers it is not an runtime error, it is linking error Source:

Answered by: shrads | Date: 4/20/2010 | Contact shrads Contact shrads

yes, we can write c program without main function ,but this program can't execute without main function.
some errors can you found.
so, boy you write with main...., Source:

Answered by: ritu raj | Date: 4/24/2010 | Contact ritu raj Contact ritu raj

Ya it is not possible to execute a C program without main though u can compile it successfully.
Compiler will check for only syntactical errors.
It never bother about whether the main is present in the program or not.
It is possible to execute a program without main in java but not in C. Source:

Answered by: Ravinder Reddy | Date: 5/18/2010 | Contact Ravinder Reddy Contact Ravinder Reddy

we can write a c program without main function using PreProcessors.

#define k 5
#define n 12
#if (n>k) printf("n is big campare to k ");
#elif printf("n is small campare to k");
#endif Source:

Answered by: Bharat kumar .G | Date: 6/17/2010 | Contact Bharat kumar .G Contact Bharat kumar .G

Hi Friends..

See the above code which is posted by Venkat..That code will works but at there also internally void()methods called by the processor. Source:

Answered by: Kiran Kuma Kala | Date: 7/29/2010 | Contact Kiran Kuma Kala Contact Kiran Kuma Kala

yes, we can write but in the linking time it will throw error
undefined reference to main
ld returned one exit status Source:

Answered by: iranna | Date: 7/31/2010 | Contact iranna Contact iranna

according to me,program can be written without main() but it will not run because before runing the program compiler will not compile the program without main(). Source:

Answered by: vikash chesi | Date: 8/6/2010 | Contact vikash chesi Contact vikash chesi

If you have the better answer, then send it to us. We will display your answer after the approval

Rules to Post Answers in

  • 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.

Post your answer here

Inform me about updated answers to this question.
Related Questions
View Answer
Tell me answer for this statement
- C Basics Interview Questions & Answers" class="btn btn-primary btn-xs">View Answer
Difference between :- 1) C and C++
2) main() in c and main() in c++ ?
View Answer
What is :- Asembler , compiler , Preprocessor , laxical analysis , parsing ?
View Answer
How can we use data connectivity in 'c' language?
View Answer
Write a program for result management system of a college ?
View Answer
Is it possible to print graphics output in C?
View Answer
How can C programs run without header files?
View Answer
What is c graphics?
View Answer
write a program for printing when i press a key next to the letter in the alphabetical order can be printed
View Answer
how to create relation calculator program using c language
View Answer
how to create love flames program using c language
View Answer
Can anyone please tell me about a website from which I could install Turbo C (compiler) for free??
View Answer
What is the use of semicolon at the end of every statement?
View Answer
What are the packages in c?
View Answer
What is object file? How can you access object file?
View Answer
Is there anything you can do in C++ that you cannot do in C ?
View Answer
What is an abstract base class?
View Answer
What is the difference between compile time error and run time error?
View Answer
What is the difference between #include <file> and #include �file�
View Answer
When we access the integer and the character variables without declaring them in program?and Why?
View Answer

Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here - Best Freshers & Experienced Jobs Website.

View All C Basics Interview Questions & Answers - Exam Mode / Learning Mode

India News Network
Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal
Cache = 0.75 Seconds