帮我看看这个C程序

来源:百度知道 编辑:UC知道 时间:2024/05/13 06:32:55
#include <stdio.h>

struct array {
int a[30];
}

size(struct array * p)
{
return sizeof(p->a)/sizeof(int);
}

int
main(void)
{
struct array ary;

printf( "the size of the array is %d\n", size(&ary) );

return 0;
}

编译报错 error C2440: 'return' : cannot convert from 'const unsigned int' to 'struct array'
请问怎么回事

其实并不是什么数据类型的问题,只是
struct array {
int a[30];
}
这里漏了一个分号,在末尾添上分号“;”
struct array {
int a[30];
};
再运行,OK

return的类型和struct的类型不一致

int size(struct array * p) /*这里没有写返回值*/
{
return sizeof(p->a)/sizeof(int);
}