Why is the function prototype inside a different function block?

前端 未结 3 1085
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-11 19:27

I am trying to understand C, by going through K&R. I have trouble understanding this code for two functions found in the book:

void qsort(int v[], int le         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-11 19:39

    You write a function prototype so that the compiler knows that function exists, and can use it. swap() is used inside qsort(), so it must appear before the line it is used. In this case, the swap() prototype is declared inside the qsort() function, but it could as well be declared before the function itself. Or you could define swap() before qsort() and remove the prototype.

提交回复
热议问题