CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Interview Success Kit - Get Success in Job Interviews Interview Success Kit - 30,000 Interview Que. & Ans.
Covers 30,000+ Interview Questions asked in actual MNC Interviews - all with model answers.
Get Your Dream Job Now - www.vyoms.com
Sponsored Links
Interview Questions
Our Services

INTERVIEW QUESTIONS C C BASICS DETAILS
Question :
Can you write a c program without using main function?

Posted by: mohammed nawaz on 12/19/2013

Contact mohammed nawaz Contact mohammed nawaz
Category C Basics Interview Questions
Rating (4.0) By 69 users
Added on 12/19/2013
Views 715
Rate it!
Answers:

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



Posted by: Ameen

Contact Ameen Contact Ameen

yes,we can write c program without using main.



Posted by: c.karuppusamy

Contact c.karuppusamy Contact c.karuppusamy

WE CAN WRITE THE PROGRAM WITHOUT MAIN.BUT,IT WILL NOT RUN.BECAUSE,THE COMPILER PERFORMS THE TASK AFTER SEEING THE MAIN FUNCTION ONLY.OTHERWISE,IT SHOWS ERROR.



Posted by: k.sangeetha

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.



Posted by: rashmi

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
2)IN THIS WORLD NOTHING IS IMPOSSIBLE HEHEHEHE.........
solution:
#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 ?);
}
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 www.gohacking.com 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 mani.konakandla@yahoo.com



Posted by: venkat

Contact venkat Contact venkat

otherwise try this one...

_start()
{
_exit(function_name())
}
void funtion_name()
{
printf("Without main
");
}


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



Posted by: Rao Sahab

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



Posted by: lol

Contact lol Contact lol

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



Posted by: sukanya

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.



Posted by: deepak

Contact deepak Contact deepak

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

see this

#include<stdio.h>
#include<conio.h>
#pragma start show()

void show()
{
printf("Hello");
}



Posted by: Swesh Mishra

Contact Swesh Mishra Contact Swesh Mishra

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

#include<stdio.h>
#include<conio.h>
{
printf("stupids we can do anything");
}



Posted by: sanjana

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.



Posted by: abhinav kumar singh

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.



Posted by: venkatesh

Contact venkatesh Contact venkatesh

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



Posted by: Latthi.k

Contact Latthi.k Contact Latthi.k

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



Posted by: naresh

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



Posted by: shrads

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



Posted by: ritu raj

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.



Posted by: Ravinder Reddy

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



Posted by: Bharat kumar .G

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.



Posted by: Kiran Kuma Kala

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



Posted by: iranna

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().



Posted by: vikash chesi

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 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.
  • Name :*
    Email Id :*
    Answer :*
    Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
    Process Verification Enter the above shown code: *
    Inform me about updated answers to this question

    Related Questions
    View Answer
    Tell me answer for this statement
    printf("printf("aim")");
    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 Vyoms.com - Best Freshers & Experienced Jobs Website.

    View ALL C Basics Interview Questions & Answers

    User Options
    Latest 20 Questions
    How to create arrays in JavaScript?
    How can JavaScript codes be hidden from old browsers that don?t support JavaScript ?
    What is namespacing in JavaScript and how is it used?
    What are the decodeURI() and encodeURI()?
    How are DOM utilized in JavaScript?
    Write the point of difference between web-garden and a web-farm?
    What is the ?Strict? mode in JavaScript and how can it be enabled ?
    What are escape characters?
    How can convert the string of any base to integer in JavaScript?
    What is the difference between ViewState and SessionState?
    Write the code for adding new elements dynamically ?
    Between JavaScript and an ASP script, which is faster?
    What are JavaScript types ?
    What qualities do you look for in a boss?
    How you would be an asset to this company?
    Why should we hire you?
    What is project implementation?
    Differentiate Public and Private Accounting?
    Explain what is compound journal entry ?
    Differentiate between provision and reserve?


    Copyright ©2003-2016 CoolInterview.com, All Rights Reserved.
    Privacy Policy | Terms and Conditions

    Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Dedicated Servers | C Interview Questions & Answers

    Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes


    Cache = 0 Seconds