Thread: Help with simple code

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    3

    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?


    Thank you for your help.


    Also I am trying to convert this into MIPS assembly language, does anyone know any good forums to ask for MIPS help??

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    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.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> 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.

  4. #4
    Railgun God |Wiz|'s Avatar
    Join Date
    Sep 2005
    Posts
    23
    Did you declare the variables beforehand?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 14
    Last Post: 11-23-2005, 08:53 AM
  2. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Windows Programming
    Replies: 0
    Last Post: 10-14-2002, 01:29 PM
  3. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 12:51 PM
  4. Simple Code, looking for input.
    By Alien_Freak in forum C Programming
    Replies: 3
    Last Post: 03-03-2002, 11:34 AM