mins315   3년 전

13행에 error: invalid conversion from ‘void*’ to ‘int*’ [-fpermissive] 이렇게 오류가 나오고 

Main.cc: In function ‘int main()’:
Main.cc:13:15: error: invalid conversion from ‘void*’ to ‘int*’ [-fpermissive]
   13 |     a = malloc(sizeof(int) * n);
      |         ~~~~~~^~~~~~~~~~~~~~~~~
      |               |
      |               void*

이렇게 나와서 컴파일 에러 라고 나옵니다. 

해결 방법을 모르겠습니다ㅠㅠ

ehdrmsl2001   3년 전

malloc은 void*를 반환해서 int*로 형변환해주셔야 합니다

mins315   3년 전

13행을 a = (int *)malloc(sizeof(int) * n); 로 고치면 아예 틀렸습니다 라고 나옵니다ㅠㅠ

어떻게 형변환 해야 하나요??

ehdrmsl2001   3년 전

형변환에서 틀린게 아니라 출력 순서가 틀렸네요.

형변환은 맞게 하셨어요.

mins315   3년 전

감사합니다ㅠㅠㅠㅠㅠㅠ

댓글을 작성하려면 로그인해야 합니다.