Array Out of Range Error

 

Hello, I would be grateful if someone could help me handle this Array Out of Size Error.

 


double b [200][1];
int OnInit()
  {

for(j=0;j<=param-1;j++)
  {

  b[j][1]=(summation/product); //correct formula 
  
  }
 
double b [200][1];
int OnInit()
  {

for(j=0;j<=param-1;j++)
  {

  b[j][1]=(summation/product); //correct formula 
  
  }

 First of all, you should code to make sure that the loop is exited if j>=199 as we don't know what value param is.

The 2nd dimension is sized [1], so it only has one index and that must be 0

b[j][1] does not exist as the 2nd dimension can only be 0 

 
GumRai:

 First of all, you should code to make sure that the loop is exited if j>=199 as we don't know what value param is.

The 2nd dimension is sized [1], so it only has one index and that must be 0

b[j][1] does not exist as the 2nd dimension can only be 0 

Yep, I have specified param as 200. What!!! even when assign column values the values begin from 0??? If i am understanding it correctly you are saying for double b[10][1] the correct way to assign is b[i][0]??? and not b[i][1]? :O
 
cryptex:
Yep, I have specified param as 200. What!!! even when assign column values the values begin from 0??? If i am understanding it correctly you are saying for double b[10][1] the correct way to assign is b[i][0]??? and not b[i][1]? :O

yes, and always make sure that i is less than 10 (in this case)

Why use a 2 dimensional array when you are only using 1 element in the 2nd dimension? 

 
GumRai:

yes, and always make sure that i is less than 10 (in this case)

Why use a 2 dimensional array when you are only using 1 element in the 2nd dimension? 

 

 

Habituated to code in MATLAB. Could you please tell how do i write the 1d array? Just b[10]?
 
cryptex:
Habituated to code in MATLAB. Could you please tell how do i write the 1d array? Just b[10]?
yes
Reason: