c++ - memory and pointers breaking before release -


the following code, during debugging, breaks before delete[] p1;. don't know how work :(

#include <iostream> #include <iomanip>  int main() {     int n = 0;     double max = 0;     std::cin >> n;     double *p1 = new double[n];     (int = 0; < n; i++) std::cin >> p1[n];     (int = 0; < n - 1; i++)     {         if (p1[i] < p1[i + 1]) max = p1[i + 1];         else max = p1[i];     }     (int = 0; < 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; } 

just typo:

for (int = 0; < n; i++) std::cin >> p1[n]; 

=>

for (int = 0; < n; i++) std::cin >> p1[i]; 

Comments