小编Wah*_*cht的帖子

C++ 函数在 endl 之后打印不需要的数字(内存变量?)

除了一个小问题之外,这段代码对我来说工作得很好。在调用 myfind_minfind_max函数之后,代码还打印出一个看似随机的数字。我认为这与引用传递有关,它是一个内存值或其他东西。有人可以解释并告诉我如何摆脱它吗?谢谢。

#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>

using namespace std;

//get_avg function will get the average of all temperatures in the array by using for loop to add the numbers

double get_avg(int* arr, int n) {
    double res = 0.0;
    for(int i = 0; i<n; i++){
        res += arr[i];

    }
    return (res/n); //average
}

void get_array(int* arr){
    int i;

    for(i=0; i<25; i++){
        arr[i] = (rand() % 100) + 1;
    }
}

//prints the …
Run Code Online (Sandbox Code Playgroud)

c++ function output

2
推荐指数
1
解决办法
1466
查看次数

标签 统计

c++ ×1

function ×1

output ×1