Notices
Results 1 to 5 of 5

Thread: c++ question:what is a main function?

  1. #1 c++ question:what is a main function? 
    Forum Freshman
    Join Date
    Nov 2009
    Posts
    11
    why is a main function necessary? what does it do? let me tell you i'm new to programming.i'm in b.sc. in a degree college


    Reply With Quote  
     

  2.  
     

  3. #2  
    Forum Freshman
    Join Date
    Oct 2008
    Posts
    19
    The main function is important because it is where your program starts. Without it the compiler would not know where to start your program from. Hope this helps.

    ~HP


    Reply With Quote  
     

  4. #3  
    Forum Freshman seoexon's Avatar
    Join Date
    Jul 2010
    Location
    London
    Posts
    18
    Main Function, as its name sounds it the Main part of your Program. It tells the compiler to where to start and what to do next. Other functions are called from this function if there are any.
    Reply With Quote  
     

  5. #4 Full description of "main()" function! 
    Forum Freshman
    Join Date
    Jul 2010
    Location
    New Delhi, India
    Posts
    17
    Hello there, I see that there are not much of the people who have given a good description of the main function. However, I will first describe the whole thing and then answer your question particularly.
    As you know that, in the programming languages like C and C++ program can be divided into multiple functions and procedures.

    Usually, the programmer writes the main function like:

    Code:
    #----Header files include here---
    void main()
    {
    -------Statements-------
    }
    A function always returns a value to the main function, but as main function can't return any value to itself we put "void" before it to make it a procedure which doesn't return a value like a function. Now, you might be understanding difference between functions and procedures.
    You can also make the main() of integer type and make it return no value in the end, like this:

    Code:
    #--------Header files include here---
    int main()
    {
    ------Statements-------
    return 0;
    }
    This way it will return 0 value which is equal to null, hence it will return no value to any other function.

    Now the answer of your question comes, why is main() necessary. Main function is necessary because no matter how long your program is the compiler starts reading the program from the main() only.[/code]
    Reply With Quote  
     

  6. #5 Re: Full description of "main()" function! 
    Forum Freshman Goddard's Avatar
    Join Date
    Nov 2009
    Posts
    48
    Quote Originally Posted by chetanbhasin
    Hello there, I see that there are not much of the people who have given a good description of the main function. However, I will first describe the whole thing and then answer your question particularly.
    As you know that, in the programming languages like C and C++ program can be divided into multiple functions and procedures.

    Usually, the programmer writes the main function like:

    Code:
    #----Header files include here---
    void main()
    {
    -------Statements-------
    }
    A function always returns a value to the main function, but as main function can't return any value to itself we put "void" before it to make it a procedure which doesn't return a value like a function. Now, you might be understanding difference between functions and procedures.
    You can also make the main() of integer type and make it return no value in the end, like this:

    Code:
    #--------Header files include here---
    int main()
    {
    ------Statements-------
    return 0;
    }
    This way it will return 0 value which is equal to null, hence it will return no value to any other function.

    Now the answer of your question comes, why is main() necessary. Main function is necessary because no matter how long your program is the compiler starts reading the program from the main() only.[/code]
    You have really bad grammar, despite the effort and attempt at using proper punctuation. I think you should stick to explaining things in your native language.

    I think everyone explained the main function sufficiently without being long winded.
    Reply With Quote  
     

Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •