'The code does not execute properly. Try to figure out why

int multiply(int a, char *b) 
{
return a b;
}

The code does not execute properly. Try to figure out why. c program language

Thank your kindhearted help ! the question has been solved simply by me, thank everyone!

int multiply(int a, int b) 
{
return a*b;
}
c


Solution 1:[1]

There's more than one error in there. First, you can't return two variables in the same function, you should return a or the content of the pointer that the variable b in pointing to. So, you could either use:

return a;

to return the variable a.

or you could use

return *b;

to return the content of the adress that b is pointing to.

If you want to multiply, as the name of the function, you should use:

return a*(*b)

Solution 2:[2]

Your function need to return an integer

int multiply(int a, char *b)

but you try to return an int (a) and a char* (b) if you want to return b (and only b) use

char *multiply(int a, char *b)

Solution 3:[3]

You must create a variable that the result will be the multiplication of the parameters and then return the value like the created variable, as I showed.

int multiply (int a, int b) {

    int result;

    result = a * b;

    return(result);

}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Guildsmac
Solution 2 Saren
Solution 3 Slava Rozhnev