gpt4 book ai didi

c++ - 释放前内存和指针中断

转载 作者:行者123 更新时间:2023-11-28 00:13:58 24 4
gpt4 key购买 nike

<分区>

以下代码在调试期间总是在 delete[] p1; 之前中断。我不知道如何让它工作:(

#include <iostream>
#include <iomanip>

int main() {
int N = 0;
double max = 0;
std::cin >> N;
double *p1 = new double[N];
for (int i = 0; i < N; i++) std::cin >> p1[N];
for (int i = 0; i < N - 1; i++)
{
if (p1[i] < p1[i + 1]) max = p1[i + 1];
else max = p1[i];
}
for (int i = 0; i < N; i++)
{
if (p1[i] == max) continue;
else std::cout << std::setprecision(2) << std::fixed << p1[i] << '\n';
}**strong text**
std::cout << std::setprecision(2) << std::fixed << max << '\n';
delete[] p1;
return 0;
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com