关于将函数作为参数传递给函数的问题 [英] Question about passing function as arguments to function

查看:70
本文介绍了关于将函数作为参数传递给函数的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <iostream.h>
#include <conio.h>
void main()
{
  clrscr();
  int sum(int );
  int mynumber=20;

  mynumber=sum(mynumber);
  cout<<mynumber;

  getch();

}



int sum(int number)

{



  number=number+5;

  return number;



}





我的问题是从上面我认为我已经修改了变量实际mynumber的值而没有使用传递指针作为参数来运行



那么为什么我们指针作为函数的参数



my question is that from above i think i have change the modify the value of variable actual mynumber with out using passing pointer as arguments to function

then why we pointers as arguments to function

推荐答案

Quote:

我想我已经改变了修改变量实际mynumber的值而没有使用传递指针作为函数的参数

e i think i have change the modify the value of variable actual mynumber with out using passing pointer as arguments to function



不,你没有。

您实际使用在 main 函数中修改了 mynumber sum 函数提供的返回值。


No you did not.
You actually modified mynumber in the main function using the return value provided by the sum function.


这篇关于关于将函数作为参数传递给函数的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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