why void and why not void as a return type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ajit Bhoravkar
    New Member
    • Sep 2010
    • 4

    #1

    why void and why not void as a return type

    As a method returns a int value we have return type as a int and if method returns nothing we use return type as a void.
    If the method is not returning anything then why should we use void. I know that without giving the return type to a method it will give an error. But my question is why void if a method return nothing.
    eg:
    void abc()
    {
    stat1;
    ....;
    }
    why not
    abc()
    {
    stat1;
    ....;
    }
  • Subin Ninan
    New Member
    • Sep 2010
    • 91

    #2
    Code:
    abc()
    {
     ....
    }
    is a constructor. It is required to specify return type as void if method doesn't return value.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Technically, at the end of a void function you could explicitly call a
      return;
      But it is implicitly understood to behave that way.

      Comment

      Working...