一个数组的编译错误,如何改正?
- C/C++ code
#include"stdafx.h"void f(int [][5]){}int main(void){ int *buf[5]; f(buf); return 0;}
.cpp(6) : error C2664: 'f' : cannot convert parameter 1 from 'int *[5]' to 'int [][5]'
究竟错在哪里? 如何改正?
[解决办法]
void f(int []){}
int main(void)
{
int buf[5];
f(buf);
return 0;
}
数组buf[5]中数组名buf本身就是指针 ,指向数组的第一个元素地址,所以无需再加 “*”,即int *buf[5]这种写法是错误的。
[解决办法]
一维数组和二维数组的区别