How to resolve “conflicting types error” in C?

后端 未结 7 635
情话喂你
情话喂你 2021-01-27 16:33

For the following C code (for swapping two numbers) I am getting the \"conflicting types\" error for swap function:

#include 
#includ         


        
7条回答
  •  星月不相逢
    2021-01-27 17:04

    You failed to declare your swap explicitly, forcing the compiler to make assumptions about the function at the point of the call. The compiler, in accordance with C rules, will assume that swap is

    int swap(int *, int *, size_t)
    

    Later you declare your swap as

    void swap(void *, void *, int)
    

    which is obviously different from what the compiler assumed. This is the conflict the compiler is telling you about.

    Also, your void swap attempts to return 0. What were you trying to achieve by that?

    P.S. It's int main, not void main.

    P.P.S. The program is not guaranteed to produce any output if its output does not end in a new-line character.

提交回复
热议问题