Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Section Call By Semantics: Call By In Reference

---
jupytext:
  formats: md:myst
  text_representation:
    extension: .md
    format_name: myst
kernelspec:
  display_name: Python 3
  language: python
  name: python3
---

Section Call By Semantics: Call By In Reference

This program demonstrates calling by in reference in Fortran.

program call_by_in_reference
    implicit none

    print *, "5! = ", factorial(5)
    print *, "10! = ", factorial(10)
    print *, "12! = ", factorial(12)

contains

    function factorial(arg) result(fac)
        implicit none
        integer, intent(in) :: arg
        integer :: fac, n

        n = arg
        fac = 1
        do while (n > 1)
            fac = fac*n
            n = n - 1
        end do
    end function factorial

end program call_by_in_reference

The above program is compiled and run using Fortran Package Manager (fpm):

Build the Program using FPM (Fortran Package Manager)

import os
root_dir = os.getcwd()
code_dir = root_dir + "/" + "Fortran_Code/Section_Call_By_Semantics_Call_By_In_Reference"
os.chdir(code_dir)
build_status = os.system("fpm build 2>/dev/null")

Run the Program using FPM (Fortran Package Manager)

exec_status = os.system("fpm run 2>/dev/null")
 5! =          120
 10! =      3628800
 12! =    479001600