#include <iostream>
using namespace std;
int main()
{
int size = 1;
double* temperatur = new double[size];
double* temperatur_save; // don't allocate memory for this pointer.
for (int i = 0; i < 40; i++)
{
temperatur[i] = i;
//save temperatur array in temperatur_save
temperatur_save = temperatur;
//Create a new array with larger size
temperatur = new double[size + 1];
//Copy the saved values to this array
for ( int j = 0; j < size; j++ )
temperatur[j] = temperatur_save[j];
//Free unused memory
delete [] temperatur_save;
//Display values
cout << temperatur[i];
//Increase "size" by one
size++;
}
// don't use the risky, platform dependent system commands.
cin.get();
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkKewoJaW50IHNpemUgPSAxOwoKCWRvdWJsZSogdGVtcGVyYXR1ciA9IG5ldyBkb3VibGVbc2l6ZV07Cglkb3VibGUqIHRlbXBlcmF0dXJfc2F2ZTsgLy8gZG9uJ3QgYWxsb2NhdGUgbWVtb3J5IGZvciB0aGlzIHBvaW50ZXIuCgoJZm9yIChpbnQgaSA9IDA7IGkgPCA0MDsgaSsrKQoJewoJCQoJCXRlbXBlcmF0dXJbaV0gPSBpOwoJCQoJCS8vc2F2ZSB0ZW1wZXJhdHVyIGFycmF5IGluIHRlbXBlcmF0dXJfc2F2ZQoJCXRlbXBlcmF0dXJfc2F2ZSA9IHRlbXBlcmF0dXI7CgkJCgkJLy9DcmVhdGUgYSBuZXcgYXJyYXkgd2l0aCBsYXJnZXIgc2l6ZQoJCXRlbXBlcmF0dXIgPSBuZXcgZG91YmxlW3NpemUgKyAxXTsKCgkJLy9Db3B5IHRoZSBzYXZlZCB2YWx1ZXMgdG8gdGhpcyBhcnJheQoJCWZvciAoIGludCBqID0gMDsgaiA8IHNpemU7IGorKyApCgkJICAgICAgdGVtcGVyYXR1cltqXSA9IHRlbXBlcmF0dXJfc2F2ZVtqXTsKCgkJLy9GcmVlIHVudXNlZCBtZW1vcnkKCQlkZWxldGUgW10gdGVtcGVyYXR1cl9zYXZlOwkJCgoJCS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