如果有一个大小为 4 的数组,则将该数组的值发送给函数。为什么会出现警告?
#include <stdio.h>
#include <stdbool.h>
void greatestOf(int arr[], int *result) {
*result = arr[0];
for (int i = 1; i < 4; i++) {
if (arr[i] > *result) {
*result = arr[i];
}
}
}
int main() {
int arr[4], x;
printf("Input : ");
scanf("%d %d %d %d", &arr[0], &arr[1], &arr[2], &arr[3]);
greatestOf(arr[4], &x); // here warning text. When I try to use '''greatest(arr, &x)'''
printf("Greatest number: %d\n", x);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我收到以下警告消息:
#include <stdio.h>
#include <stdbool.h>
void …Run Code Online (Sandbox Code Playgroud)