Say me the answer of this, i dont know

Discussion in 'C' started by techinspiration, Apr 26, 2010.

  1. techinspiration

    techinspiration New Member

    Joined:
    Feb 14, 2010
    Messages:
    54
    Likes Received:
    0
    Trophy Points:
    0
    Hello members,

    I purchased the book "Let us C" (a great book so far) and i'm in the process on learning C, but i have a pair of questions for anyone with a little free time who can help me.

    What is the correct way for declarating the main funcion?

    I have seen examples like these: [void main(void)], [int main()] and [int main(void)].

    The book uses the second example but i think the most standard and current way is: int main(), i'm correct?

    Another question is about the return function.

    I have seen examples like these: [return(var)] and [return var].

    Should i use parentheses on return?

    Thanks in advance.
     
  2. techme

    techme New Member

    Joined:
    Feb 15, 2010
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    1. [int main(void)] & [int main()]
    both are the same.
    here the return type is integer and main is void.
    2. [void main(void)]
    here the return type and main both are void.:)
     
  3. meyup

    meyup New Member

    Joined:
    Feb 15, 2010
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    i agree with techme.
    he has said the right thing.
    you have to implement the header file where it needed.
     
  4. sainishanth

    sainishanth New Member

    Joined:
    Feb 8, 2012
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    as techme said both int main()and int main(void) are same
    but u have to return a value.
    like return 0;
    void main() and void main(void)are same here u should not use return 0;
    and parenthesis is not mandatory while returning.
    the above both return statements are valid.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice