+ 2

Void Pointer Function C programming

The following code is not working for multiplication of floating point values, while the same function was working for integer type values! In the definition of Void Pointer Function it says that only the definition part is required to be changed to except any type of argument. https://code.sololearn.com/cbC3S91HTAuF/?ref=app

14th Jun 2019, 12:39 PM
Anik De
Anik De - avatar
3 Réponses
+ 1
Two errors in your code: (1) square() returns a pointer, so it cannot return "result", but "&result" (2) a pointer cannot be assigned to a float, so sq_int must not be a float, but a "float *" Obviously the following printf must not print "sq_int" but "*sq_int"
14th Jun 2019, 1:13 PM
Bilbo Baggins
Bilbo Baggins - avatar
14th Jun 2019, 1:16 PM
Anik De
Anik De - avatar
+ 1
1. Square() does returns a pointer, it will return the type of argument which we will specify in definition. 2. And here we aren't assigning any address to sq_int , we want the result of function square (& c) to be stored in sq_int. So it is not required to specify sq_int as a pointer.
14th Jun 2019, 1:23 PM
Anik De
Anik De - avatar