c语言中为什么不能用结构体定义函数?

像这样写,在hdoj里用c语言提交为什么显示 compilation error?

第1个回答  2014-03-20
struct是一种变量类型,interval是一个变量名又怎么用来编函数呢?
其实你可以把struct看作int,char这些变量类型,这样就能明白为什么不能定义函数了。追问

是不是在struct interval中,相比于int a;struct相当于int ,interval相当于a?但是为什么我之前的写法在c-free中可以成功运行?虚心求教

第2个回答  2014-03-20
struct interval solve()追问

能详细点么?如果solve函数定义用struct interval,那下面的p是不是也要用struct interval来定义?

追答

是的。
struct interval solve(double a, double)
{
struct interval p;

...

}

追问

不好意思,刚刚试了一下,还是不对,报错compilation error

追答

报错的信息,能发出来?

本回答被提问者采纳
相似回答