printf 出现c6272的问题

运行的结果是错误的

#include

int main(void)
{
//set a array
double array[] = { 1,-0.3,6,40,17 };
double largest = array[0], smallest = array[0];

//find the largest and smallest value in array 
for (int i = 0; i < 5; i++)
{
    if (array[i] > largest) {
        largest = array[i];
    }
    if (array[i] < smallest) {
        smallest = array[i];
    }
}
    printf("the largest number is %f\n", &largest);
    printf("the smallest number is %f\n", &smallest);

    
    double sum;
    //a formular of addition
    sum = largest + smallest;
    printf("the sum of the largest and smallest is %f\n", &sum);
return 0;

}

在每一行的printf都显示c6272

img

运行后所有的数都是0

img

我想让这个数组中的最大和最小相加的和

printf("the largest number is %f\n", &largest);里面的&不要,之后的类似

#include <stdio.h>

int main(void)
{
    //set a array
    double array[] = { 1,-0.3,6,40,17 };
    double largest = array[0], smallest = array[0];
    //find the largest and smallest value in array 
    for (int i = 0; i < 5; i++)
    {
        if (array[i] > largest) {
            largest = array[i];
        }
        if (array[i] < smallest) {
            smallest = array[i];
        }
    }
        printf("the largest number is %f\n", largest);
        printf("the smallest number is %f\n", smallest);
        double sum;
        //a formular of addition
        sum = largest + smallest;
        printf("the sum of the largest and smallest is %f\n", sum);
    return 0;
} 

警告 C6272 在应该是浮点数的地方出现了非浮点数
& 表示变量地址,显然不是浮点数的

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^