I\'m writing a program that calculates the greatest common denominator of two numbers, but i\'m getting problem with malloc
function and pointers. Actually it\'
You need to cast:
int *a = (int*)malloc(num * sizeof(int));
Because there's no implicit conversion from void*
to type *
in C++.
Note that this cast is not required in C and could potentially be dangerous to do so in C.
Except for #include <iostream>
, nothing in your code is C++. So remove it and compile it with a C compiler and you wouldn't need this cast.