Function which returns multiple values

Harutaka Kawamura

In Fortran, is it possible to define a function which returns multiple values like below?

[a, b] = myfunc(x, y)
Alexander Vogt

That depends... With functions, it is not possible to have two distinct function results. However, you can have an array of length two returned from the function.

  function myfunc(x, y)
    implicit none
    integer, intent(in) :: x,y
    integer             :: myfunc(2)

    myfunc = [ 2*x, 3*y ]
  end function

If you need two return values to two distinct variables, use a subroutine instead:

  subroutine myfunc(x, y, a, b)
    implicit none
    integer, intent(in) :: x,y
    integer, intent(out):: a,b

    a = 2*x
    b = 3*y
  end subroutine

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

pandas apply function that returns multiple values to rows in pandas dataframe

Multiple returns in python in a function

How to write Java function that returns values of multiple data types?

Implement a function which returns a pointer

How to write the types explicitly on the left when the function returns multiple values?

How to differentiate between assigning and declaring values from a function with multiple returns?

Multiple returns from a function

JavaScript Function Returns Multiple Values as Object in ES6

How can I map a function on dataFrame column values which returns a dataFrame?

How to test function which returns function with parameters?

Write an R function which accepts a list of integers and returns only the odd values in the original list

Testing a function which returns an object that returns a function which return a boolean

Method signature of the function which returns multiple value in C#

Implementing a function which returns function definition as string

Returns multiple values from a PHP function

Updating the Values of Multiple Instances of a React Component Returns .map is not a function

The function returns invalid values

Summarize with a function that returns multiple values in a list

Function which returns function scheme

A Function Which Returns Parent Functions

PHP, checkbox which returns multiple values (rows)

SELECT from function which returns multiple columns

Multiple ajax returns and sum values

How to use a function that returns multiple values in dplyr::across()?

Is this possible to design a function which takes a parameter and returns an object which holds multiple properties or functions

function returns multiple values, assignment to tuples with different number of entries?

writing an if-else function which returns 2 values

Apply custom function that returns multiple values after dplyr::rowwise()

Which PHP function returns a smaller version of my associative array containing only keys present as values in a second array?