小编New*_*mer的帖子

为什么将 4 元素数组传递给 C 中的函数时会出现警告?

如果有一个大小为 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)

c arrays arguments function function-call

0
推荐指数
1
解决办法
150
查看次数

标签 统计

arguments ×1

arrays ×1

c ×1

function ×1

function-call ×1