C编程警告:控制到达非void函数结束[-Wreturn型]}
代码:
struct battleship makeShip (int size, int pos)
{
int i, j;
int* body;
body = (int*) malloc (size * sizeof(int));
for (i = pos; i < (pos + size); i++){
for (j=0; j < size; j++){
body[j] = 1;
}
}
}
不知道,如果我尝试并添加回报是什么原因造成的错误0 ;我得到:
错误:从不兼容的结果函数返回'int' 类型'struct battleship' return 0;
你不能有不同的返回类型。如果函数类型是int,那么只有你可以返回int。如果你使用其他类型,它会抱怨。 – LethalProgrammer
甚至没有在你的函数中定义的“struct battleship”变量,所以不确定你为什么要返回一个 –