0
Square function casting in C
"This square function has been written to multiply ints, which is why the num void pointer is cast to an int. If the implementation were to be changed to allow square() to multiply floats, then only the definition need be changed without having to make changes to the declaration." Then Can you suggest me a code with editing following code only by changing definition. I am completely new to C. https://code.sololearn.com/cbAAS26GeVK6/?ref=app
2 Respuestas
+ 4
void* square (const void *num) {
static float result;
result = (*(float *)num) * (*(float *)num);
return(&result);
}
Of course, the stuff in the main function needs to be adjusted to using float. But the point that this lesson wants to bring home is that the function declaration,
void* square (const void *);
has not changed.
+ 3
Right :) But I also said that you need to adjust the stuff in main ;)
Think about what you are returning now, and how you need to change the main function to make it all fit together.