What is return type?how can we use it?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sivakoti
    New Member
    • Aug 2010
    • 4

    What is return type?how can we use it?

    What is return type?how can we use it?
  • wild wolf
    New Member
    • Aug 2010
    • 5

    #2
    it is so complex a question . it accords to your needs and your definition. for example ,the funtion: int salary();then it will a type of integer .

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      The return type is used when you want your function to be an RVAL.

      In this code:

      Code:
      int data = 10;
      The 10 is an RVAL (the value is to the right of the = operator). data is the LVAL.

      If the 10 need to be calculated, then you can use a function that returns an int:

      Code:
      int data = Calculate();
      The compiler will call the function to get the int to assign to data. Calculate() is now an RVAL.

      Comment

      • whodgson
        Contributor
        • Jan 2007
        • 542

        #4
        Yes...and at its simplest it is demonstrated by functions.
        Code:
        int convert(double x)
        {x/=12;
        return x;}
        double x is passed to convert(),conve rted to feet and returned as an int (the function type)

        Comment

        • donbock
          Recognized Expert Top Contributor
          • Mar 2008
          • 2427

          #5
          The starting point is with functions: what a function is and how it can be used. Let us know if you have questions about that.

          Some languages (such as VisualBasic.NET , Pascal, Fortran, Ada) make a distinction between subroutines and functions. They consider a subroutine to be a callable block of code; while a function is a subroutine that also returns a value.

          In C, both are called functions. However, a function that returns void is analogous to a subroutine.

          You don't include a return value in a function definition for the fun of it -- you do it if and only if it makes sense to you for a value of some sort to be associated with the function. If you can't think of any useful value to return then define the function to return void.

          Comment

          Working...