Array Out of Range Error

Back to topics list To post a new topic, please log in or register
avatar
85
cryptex 2015.08.17 06:07
 

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 
  
  }

 

avatar
Moderator
3406
GumRai 2015.08.17 06:56 #
 
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 

avatar
85
cryptex 2015.08.17 20:07 #
 
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
avatar
Moderator
3406
GumRai 2015.08.18 01:28 #
 
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? 

 

 

avatar
85
cryptex 2015.08.18 06:10 #
 
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]?
avatar
Moderator
3406
GumRai 2015.08.18 07:15 #
 
cryptex:
Habituated to code in MATLAB. Could you please tell how do i write the 1d array? Just b[10]?
yes
Back to topics list  

To add comments, please log in or register