Why this program is not compile in dev c++ compiler? | SoloLearn: Learn to code for FREE!

+1

Why this program is not compile in dev c++ compiler?

#include <stdio.h> void * square (const void *num); int main() { int x, sq_int; x = 6; sq_int = square(&x); printf("%d squared is %d\n", x, sq_int); return 0; } void* square (const void *num) { static int result; result = (*(int *)num) * (*(int *)num); return(result); }

c

5/26/2020 9:59:27 AM

Saurabh Yadav

1 Answer

New Answer

+2

The program should compile with warnings unless your compiler is set to report warnings as errors and also you are compiling it as a C program not as C++. Anyways sq_int = square(&x); trying to assign/make an int from void*. square returns void* not int do sq_int = *(int*)square(&x); in function square return(result); result in an int not a pointer. The code is trying to convert int to void* do return &result;