제출 #13693

#제출 시각아이디문제언어결과실행 시간메모리
13693taehoon1018최댓값 (tutorial2)C++98
컴파일 에러
0 ms0 KiB
#include <stdio.h> int GetMax(int n, int* p) { int i,max; max = *p; for(i=0;i<n;i++) { if(*(p+i)>*p) max = *(p+i); } return max; } int main() { int A[10]; int i; int n, max; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d", A+i); } max = GetMax(A,n); printf("%d", max); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

tutorial2.cpp: In function ‘int main()’:
tutorial2.cpp:31:19: error: invalid conversion from ‘int*’ to ‘int’ [-fpermissive]
   max = GetMax(A,n);
                   ^
tutorial2.cpp:3:5: note: initializing argument 1 of ‘int GetMax(int, int*)’
 int GetMax(int n, int* p)
     ^
tutorial2.cpp:31:19: error: invalid conversion from ‘int’ to ‘int*’ [-fpermissive]
   max = GetMax(A,n);
                   ^
tutorial2.cpp:3:5: note: initializing argument 2 of ‘int GetMax(int, int*)’
 int GetMax(int n, int* p)
     ^
tutorial2.cpp:24:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&n);
                 ^
tutorial2.cpp:28:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", A+i);
                     ^