beginner help

Discussion in 'Mac Programming' started by crazyg, Jun 6, 2006.

  1. macrumors newbie

    Joined:
    Jun 6, 2006
    #1
    im new to C++, and need help. How do you initialize an array of say 50 elemnets (the first 25, give them the same value, then give the last 25 another value)
    Thanks
     
  2. macrumors regular

    Joined:
    Jun 4, 2006
    Location:
    B-Town, India
    #2
    Don't know enough about C++ to help you out, but if it's anything like C:

    Code:
    http://www.gamedev.net/reference/articles/article1697.asp
    Probably the best pointer and array tutorial I've ever seen. Is C++ your first language?
     
  3. thread starter macrumors newbie

    Joined:
    Jun 6, 2006
    #3
    Thanks

    no Java is, have also done a bit of c but not enough, thanks for the tutorial looks good
     
  4. macrumors 6502a

    Palad1

    Joined:
    Feb 24, 2004
    Location:
    London, UK
    #4
    here goes
    PHP:
    int max=50;
    int firstVal=42;
    int secondVal=667// phew that was close
    int mid=max/2;
    intarIntegers=new int[max];
    for(
    int i=0;i<max;i++){
     
    arIntegers[i]= i<mid?firstVal:secondVal;
    }

    // use your array then when done with it
    delete arIntegers// i'm not quite sure, it's been a while since I last used manual memory management..


     

Share This Page