[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]


    Search the Q&A Archives


1)what is the use of simply writing main() { }...

<< Back to: comp.lang.c Answers to Frequently Asked Questions (FAQ List)

Question by balu
Submitted on 7/22/2003
Related FAQ: comp.lang.c Answers to Frequently Asked Questions (FAQ List)
Rating: Not yet rated Rate this question: Vote
1)what is the use of simply writing
  main()
   {
   } only?

2)what happens while executing
  main()
  {
    main()
      {
      }
   }



Answer by Manju
Submitted on 8/11/2003
Rating: Not yet rated Rate this answer: Vote
1) In this program, main{}, it doesn't do anything, simply executes

2) And here, it calls the main again and again, it will lead to infinite loop.

 

Answer by Biju
Submitted on 9/5/2003
Rating: Not yet rated Rate this answer: Vote
1) In this program, main{}, it doesn't do anything, simply executes

2) You cannot call a main function from a function also ; is missing after main()

 

Answer by chittem.v.n.sanyasi rao
Submitted on 9/16/2003
Rating:  Rate this answer: Vote
1. thew empty function just executes it body only.
2. it is an infinite loop.

 

Answer by raghuveer
Submitted on 12/9/2003
Rating: Not yet rated Rate this answer: Vote
1) Does Nothing
2) Error... u cant define a function with in other function

 

Answer by Raj
Submitted on 2/23/2004
Rating:  Rate this answer: Vote
The point is, to start of with c programming, main must be the first calling function which is built-in fucntion.

If u do that by calling the same function, it is improper b'cos the concept of c programming is ruled out.

But u can make other built-in or U.D.Functions to be called inside the main which gives recursive as its meaning.


 

Answer by Daniel
Submitted on 3/24/2004
Rating:  Rate this answer: Vote
2. This looks like an attempt to redefine main inside main; and in C you can't define a function within another function. (This limitation was made to simplify the job of compiling the C language.) But if you meant to CALL main from inside main, as in:
main(){
    main();
}
then this is indeed legal; you can indeed call main recursively from inside main. Of course if you don't put any other qualifiers on it, it'll be an infinite recursion, you'll overflow the stack, and crash the program. But try this one:
#include <stdio.h>
main(){
    int c;
    if ((c=getchar())!=EOF){
       main();
       putchar(c);
    }
}
This is a perfectly legitimate program that reverses its input.

 

Your answer will be published for anyone to see and rate.  Your answer will not be displayed immediately.  If you'd like to get expert points and benefit from positive ratings, please create a new account or login into an existing account below.


Your name or nickname:
If you'd like to create a new account or access your existing account, put in your password here:
Your answer:

FAQS.ORG reserves the right to edit your answer as to improve its clarity.  By submitting your answer you authorize FAQS.ORG to publish your answer on the WWW without any restrictions. You agree to hold harmless and indemnify FAQS.ORG against any claims, costs, or damages resulting from publishing your answer.

 

FAQS.ORG makes no guarantees as to the accuracy of the posts. Each post is the personal opinion of the poster. These posts are not intended to substitute for medical, tax, legal, investment, accounting, or other professional advice. FAQS.ORG does not endorse any opinion or any product or service mentioned mentioned in these posts.

 

<< Back to: comp.lang.c Answers to Frequently Asked Questions (FAQ List)


[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]

© 2008 FAQS.ORG. All rights reserved.