This question already has answers here:
Closed 6 months ago.
passing argument makes pointer from integer
(4个答案)
warning: passing argument 1 of ‘calculation’ makes pointer from integer without a cast [enabled by default]
(1个答案)
我想初始化一个5x6数组,并将其传递给函数,在该函数中获取数组的每一列的和。但是我一直收到警告,我应该在哪里修复?
(4个答案)
warning: passing argument 1 of ‘calculation’ makes pointer from integer without a cast [enabled by default]
(1个答案)
我想初始化一个5x6数组,并将其传递给函数,在该函数中获取数组的每一列的和。但是我一直收到警告,我应该在哪里修复?
int sutuntopla(int b[5][6], int uzunluk)
{
int i,j;
int sum = 0;
for(j = 0 ; j < uzunluk ; j++ )
{
for(i=0;i<5;i++)
{
sum+=b[i][j];
}
printf("Sutun %d toplami=%d\n",(j+1),sum);
sum=0;
}
}
int main(int argc, char *argv[])
{
int a[5][6] = {{1,2,3,4,5,6},{7,8,9,5,6,7},{1,2,5,6,7,8},{1,3,8,9,10,9},{1,4,4,4,5,6}};
sutuntopla(a[5][6],6);
return 0;
}
最佳答案
此代码将起作用。
//Here you can make the return type void
int sutuntopla(int b[5][6], int uzunluk)
{
int i,j;
int sum = 0;
for(j = 0 ; j < uzunluk ; j++ )
{
for(i = 0 ; i < 5 ; i++ )
{
sum += b[i][j];
}
printf("Sutun %d toplami=%d\n", (j+1), sum);
sum = 0;
}
}
int main(int argc, char *argv[])
{
int a[5][6] = {{1,2,3,4,5,6},{7,8,9,5,6,7},{1,2,5,6,7,8},{1,3,8,9,10,9},{1,4,4,4,5,6}};
sutuntopla(a, 6);
//When you are passing an array, you just write its name,
//like here for a.
//It passes the base address of the array to the function.
return 0;
}
关于c - 如何解决:传递'sutuntopla'的参数1使指针从整数变为无强制转换警告? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56307345/