# Help with simple code

• 10-13-2005
shin
Help with simple code
Hello eveyrone, this is my first time looking at the C++ programming language and I have a question.

The following code

Code:

```for(i=0; i!=4; i++){ a[2i]=b[i]+i; }```
In understand that in this for loop that i starts at 0 and increments by 1 until it is 4, however I am not sure what is going on inside of it.

does it mean

a[2(1)]=b[1]+1;
a[2(2)]=b[2]+2;
.
.
.
.
a[2(4)]=b[4]+4;

Stop (or does it stop at 3??)

does a[2(2)]=b[2]+2; mean that the value of the 8th element in array a = the value of the second element in array b plus 2?

Also I am trying to convert this into MIPS assembly language, does anyone know any good forums to ask for MIPS help??
• 10-13-2005
orbitz
a[2i] is a syntax error. 2i is a gcc extension for complex number literals. Perhaps you mean a[2*i]. And why you would wan tto do that is qutie confusing.
• 10-13-2005
Daved
>> Stop (or does it stop at 3??)

It stops at 3.

Also, array indexes are 0 based, so:

a[3] = b[2] + 1

means the 4th element of a is assigned the value of the third element of b plus 1.
• 10-14-2005
|Wiz|
Did you declare the variables beforehand?