It is being called at the end of program, in the "delete" sequence, I guess. The program is working well all the way, except the end.
#include <iostream>
#include <cmath>
//Завдання 2, покажчикі
using namespace std;
int main()
{
int n = 10;
cout << "Input N (size of arrays): ";
cin >> n;
float* X = new float[n+1];
float* A = new float[n + 1];
float* max;
float* B = new float[n];
cout << "Input your X array (10 elems): " << endl;
//Логарифм від нуля завжди буде нескінченністю, отже, маємо рахувати з 1
for (int i = 1; i <= n; i++) {
cin >> X[i];
A[i] = cos(pow(X[i], 2)) + 4.5 * pow(log(pow(i, 2)), 2) + i;
}
max = new float( A[1]);
cout << "Your A array: " << endl;
for (int i = 1; i <= n;i++) {
if (A[i] > *max) max = &A[i];
cout << A[i] << " ";
}
cout << "\nYour B array: " << endl;
for (int i = 0; i < n; i++) {
B[i] = A[i + 1] / *max;
cout << B[i] << " ";
}
delete max;
delete[] X, A, B;
}
I tried to initialize max at the begining, giving it value of &A[0] (I know arrays are filled with random values when initialized, it doesn't matter). Then, I tried to initialize it in the first "for" loop like:
for (int i = 1; i <= n; i++) {
cin >> X[i];
A[i] = cos(pow(X[i], 2)) + 4.5 * pow(log(pow(i, 2)), 2) + i;
if (i == 1) max = &A[i];
else if (A[i] > *max) max = &A[i];
}