Use of int, return, and void

Discussion in 'C' started by imported_chichi, Aug 24, 2011.

  1. imported_chichi

    imported_chichi New Member

    Joined:
    Aug 23, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Hello everybody,
    I am new to C language and I ve fallen in love with it. I would like to do allsotrs of things with C, from high level to low stuff like programming microcontrollers. My question is on the main function and the return statement. Why is int included at the beginning of the main function even though the function is not returning an interger:

    int main ()
    { printf("Hello World!\n");

    return 0;

    }
    This function returns a strings and why do we have to include the int? Secondly whats the purpose of the return 0;?
    When do we use void?
     
  2. gpk kishore

    gpk kishore New Member

    Joined:
    Jun 30, 2011
    Messages:
    82
    Likes Received:
    0
    Trophy Points:
    0
    sir
    when we are using void in our program it means that we are not returning anything to our required function
    i,e..,
    void main()
    {
    printf("cfanatic);
    }
    void ,int ,char,float before main are called as return type
    it means that if we use
    int as return type in our program
    int main()
    {
    printf("CFANATIC");
    return 0; //since we have mentioned return type as int we should return int value to function
    }
     
  3. imported_chichi

    imported_chichi New Member

    Joined:
    Aug 23, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Thank you. Give me a function that returns something. Isn't contradictory for an int main () function to have a return 0; at the end?
     
  4. imported_sampada

    imported_sampada New Member

    Joined:
    Aug 27, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Location:
    Pune
    i want 2 learn C......

    .plz.....give me suggetion.........how?????????????
     
  5. gpk kishore

    gpk kishore New Member

    Joined:
    Jun 30, 2011
    Messages:
    82
    Likes Received:
    0
    Trophy Points:
    0
    that is not a contradictory
    since u have mentioned return type as int u have to return something
    otherwise it would be warning when u compile in turboc as
    "Function should return a value"
     

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