I had a discussion with my professor recently about the program I am currently working on. I explained to him that when I tried to initialize thousands of values in my arrays, my program has some problems in running.
For example:
1 2
#define NMAX 500
float aLU[NMAX][NMAX + 1];
These codes are not executed and thus the C++ compiler tells me that it not executable and has some problems with exceptionals and probe pages.
As a solution of my professor, he told me to replace this "static" coding to "dynamic" coding of arrays.
For example of static:
float a[10][5];
For example of dynamic:
1 2 3 4 5
float **a;
a = new (*float) [10];
for (int i=0,i<10; i++){
a[i]=newfloat [5];
}
For the dynamic, I tried to type these codes to my C++ program, but at some point, it is not working, what is the wrong in my code? Thank you in advance.
Provided that I think there is no problem with it?? :/
My professor advised me to use it but it seems like it is not working properly... I also saw the same format from the StackOverFlow but why it is not working properly... :S
int **board;
board = newint*[10]; // dynamic array (size 10) of pointers to int
for (int i = 0; i < 10; ++i) {
board[i] = newint[10];
// each i-th pointer is now pointing to dynamic array (size 10) of actual int values
}
I think I have found now the issue why it is not working...
Hayssstt... Why I haven't noticed it... So shame of myself... :/
All I need to do is... if I am going to use the pattern I have shown above:
1 2 3 4
float **a= newfloat*[1000];
for (int i = 0; i < 1000; i++) {
a[i] = newfloat[1000];
}
All I have to do is to make sure that I initialized the line 1 "before" the int main() function...
...and the lines 2-4 should be incorporated inside the int main() function...
Example:
1 2 3 4 5 6 7 8 9 10 11 12
#include <iostream>
float **a= newfloat*[1000];
int main(){
for (int i = 0; i < 1000; i++) {
a[i] = newfloat[1000];
}
return 0;
}