[Solved] Swap number bug


As others have pointed out, you can only have one return statement from a function and thus only return on parameter (although it can be a structure).

In this instance I would pass the integer values into the function by using integer pointers and passing their address e.g.:

int swapNum(int *num1, int *num2);
int main()
{
    int a = 2;
    int b = 3;
    printf("a=%d   b=%d\n",a,b);
    
    swapNum(&a, &b);
    printf("a=%d   b=%d\n",a,b);

    return 0;
}

int swapNum(int *num1, int *num2)
{
    int tempNumber;
    tempNumber = *num1;
    *num1 = *num2;
    *num2 = tempNumber;
    return 0;
}

Output

a=2   b=3
a=3   b=2

3

solved Swap number bug