Thread: main prototype / main.h

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    44

    main prototype / main.h

    I was just curious, but since the prototype of main can be
    int main(void) or int main(int argc, char *argv[])
    is there a main.h or how is this being taken care of? And can you change these parameters?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It is more like those can be the return type and signature of the main function. You do not actually write a prototype for it. You can certainly use your own parameter names if you prefer, and depending on the (compiler) implementation more parameters may be available.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    44
    but i thought parameters for a function were declared in the prototype of the function and the return type is what is infront of the function name, so the return type is always int?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by boxden
    but i thought parameters for a function were declared in the prototype of the function
    They are, if you wish to provide the prototype and later (or in another place) define the function. But the main function is usually defined without a prototype, since it is not usually called from within the program.

    Quote Originally Posted by boxden
    and the return type is what is infront of the function name, so the return type is always int?
    Yes, though there are exceptions that you need not worry about.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. loading vectors and data before main
    By lawrenced in forum C++ Programming
    Replies: 8
    Last Post: 07-30-2009, 01:42 PM
  2. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  3. int main (), main (), main (void), int main (void) HELP!!!
    By SmokingMonkey in forum C++ Programming
    Replies: 7
    Last Post: 05-31-2003, 09:46 PM
  4. what to do with the main window
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 01-28-2003, 08:58 PM
  5. void or int for main?:)
    By bigtamscot in forum C Programming
    Replies: 13
    Last Post: 09-27-2001, 03:11 AM