【发布时间】:2012-01-21 13:28:31
【问题描述】:
#include "stdafx.h"
#include "stdio.h"
#include "math.h"
#include "stdlib.h"
void test (int a,int *b, int result[], int serie[]);
int main()
{
int *serie = malloc(sizeof(int));
int result[20], a,b, i;
a=0;
b=0;
for (i = 0; i < 20; i++) {
result[i]=i+10;
serie[i]=rand();
printf("result is %d \n",result[i]);
}
test(a,&b,result,serie);
printf("value of a inside main %d \n",a);
printf("value of b inside main %d \n",b);
for (i = 0; i < 20; i++) {
printf("value of result inside main is %d and of serie is %d \n",result[i],serie[i]);
}
getchar();
return 0;
}
void test(int a, int *b, int result[], int serie[]) {
int i;
a=13;
*b=14;
printf("value of a inside the function %d \n",a);
printf("value of b inside the function %d \n",*b);
for (i = 0; i < 20; i++) {
result[i]=result[i]*2;
serie[i]=7;
printf("value of result inside the function is %d and of serie is %d\n",result[i],serie[i]);
}
}
基本上,这些代码所做的只是查看变量的范围,我写它是为了帮助自己,我想用一个函数来改变main 内的整数值(参见int b)你必须调用它使用&b (test(a,&b,result,serie);),然后在函数*b 中。所以我正在尝试对数组进行这种操作 &* 但它们不起作用。
看来你所要做的就是写数组void test(... int result[],int serie[]) 并调用函数只需将名称放在不带括号的位置:test(...,result,serie); 我说的对吗?
如果我只想更改函数内部的数组,比如使用变量 a,该怎么办?
【问题讨论】: