函数可以调用主函数中定义的变量吗
来源:百度知道 编辑:UC知道 时间:2024/06/27 14:45:37
把主函数的变量当参数穿进去不就行了?
int Call(int definedInMain)
{
//do something with definedInMain
}
int main()
{
int definedInMain=0;
Call(definedInMain);
}
如果要改变主函数中的变量本身,则改变传入方式为引用即可:
int Call(int& definedInMain) //按引用传入
{
//do something with definedInMain and change it
}
int main()
{
int definedInMain=0;
Call(definedInMain);
}
以下程序通过函数指针P调用函数fun(),请在空格处写出定义变量P的语句。
定义函数返回两个中较大数,在主函数中调用该函数求三个数中较大的数并输出
c++中定义函数变量时变量前的*代表什么意思?如countrs(int*bd)
asp.net(c#)中,在private void XX(){} 里面,如何定义公共变量,供其他函数调用?
主函数定义数组a[10],从键盘输入十个数,然后调用自定义函数求出最小的元素,最后在主函数中输出结果
编译程序时它说本地函数定义不合法,而这函数我是在其他函数中调用的,是什么原因呢
javascript函数调用和FORM表单中变量问题
java中静态函数中为什么不能定义static变量?
ASP如何调用定义函数
javascript中可以调用javabean写的函数吗?