以下是引用飘青在2012-8-19 19:33:02的发言:
呵呵,我没有别的意思。 这两个的区别。 希望您帮我解答
一:
在主函数中
score[]={1,2,2}
float *p
p=search(score,2);
自定义函数中:
float saerch(float (*pointer),int n)
{
float *p;
p=pointer+1;
return (p);
}
二:
在主函数中
score[]={1,2,2}
float *p
p=search(score,2);
自定义函数中:
float *saerch(float (*pointer),int n)
{
float *p;
p=pointer+1;
return (p);
}
的区别? 我越看到后面疑惑越大。
程序代码:
#include <stdio.h>
float saerch(float (*pointer),int n)
{
float *p;
p = pointer + 1;
return (p);
}
int main(void)
{
float score[] = {1,2,2};
float *p;
p = search(score,2);
}
错误就在挂羊头卖狗肉 明明是返回指针 但函数定义的时候却说自己返回是是变量
Compilation started at Sun Aug 19 19:39:25
gcc aaa.c -Wall
aaa.c: In function 'saerch':
aaa.c:7:2: error: incompatible types when returning type 'float *' but 'float' was expected
aaa.c: In function 'main':
aaa.c:14:2: warning: implicit declaration of function 'search' [-Wimplicit-function-declaration]
aaa.c:14:4: warning: assignment makes pointer from integer without a cast [enabled by default]
aaa.c:13:9: warning: variable 'p' set but not used [-Wunused-but-set-variable]
aaa.c:15:1: warning: control reaches end of non-void function [-Wreturn-type]
aaa.c: In function 'saerch':
aaa.c:8:1: warning: control reaches end of non-void function [-Wreturn-type]
Compilation exited abnormally with code 1 at Sun Aug 19 19:39:25
看看编译器说了什么