通过引用传递参数传递交换函数 [英] Passing arguments by pass-by-reference to a swap function

查看:162
本文介绍了通过引用传递参数传递交换函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在解决练习测试时遇到了这个问题。考虑下面的代码以
FORTRAN之类的传递引用语言编写,并且这些语句代码

 子程序交换(ix,iy)
it = ix
ix = iy! L1行
iy = it!在线L2
结束

程序主要
ia = 3
ib = 8
调用交换(ia,ib + 5)
print * ,ia,ib
最终计划

陈述:


  1. 编译器将生成代码来分配一个临时无名单元,
    将其初始化为13,并传递单元交换的地址
  2. 执行时,代码将在第L1行生成运行时错误。

  3. 执行时,代码将在第二行生成运行时错误。程序将打印13和8

  4. 程序将打印13和-2

上面的声明是正确的。



我认为S1和S4。任何人都可以确认吗? TIA

解决方案

是的,S1和S4都是正确的。



S0a:由于L1:和L2:是语法错误,所以文件不可编译。 :)

S0b:严格来说,FORTRAN作为参考传递语言是不正确的:



I encountered this problem while solving a practice test

Consider the following code written in a pass-by-reference language like FORTRAN and these statements about the code

  subroutine swap(ix,iy)
    it = ix
    ix = iy    ! line L1
    iy = it    ! line L2
  end

  program main
    ia = 3
    ib = 8
    call swap (ia, ib+5)
    print *, ia, ib
  end program

Statements:

  1. The compiler will generate code to allocate a temporary nameless cell, initialize it to 13, and pass the address of the cell swap
  2. On execution the code will generate a runtime error on line L1
  3. On execution the code will generate a runtime error on line L2
  4. The program will print 13 and 8
  5. The program will print 13 and -2

Which of the above the above statement(s) is/are correct.

I think S1 and S4. Could anyone please confirm? TIA

解决方案

Yes, S1 and S4 are correct.

Also,

S0a: The file is not compilable as is because the L1: and L2: are syntax errors. :)

S0b: Strictly speaking, speaking of FORTRAN as a pass-by-reference language is incorrect:

这篇关于通过引用传递参数传递交换函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆