Array Question

This is a discussion on Array Question within the C++ Programming forums, part of the General Programming Boards category; Can you declare whole rows of a multi-dimensional array at one time? or do you have to go through and ...

  1. #1
    Registered User Octorok101's Avatar
    Join Date
    May 2002
    Posts
    22

    Array Question

    Can you declare whole rows of a multi-dimensional array at one time? or do you have to go through and individually declare each spot one at a time?

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Code:
    int x[][5] = { { 1, 2, 3, 4, 5 },
                   { 2, 4, 6, 8, 10 } };
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User Octorok101's Avatar
    Join Date
    May 2002
    Posts
    22
    I cant seem to get it to work. What are the second group of numbers for?

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Try this:
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main(void)
    {
      int x[2][5] = { 
        { 1, 2, 3, 4, 5 },
        { 2, 4, 6, 8, 10 } 
      };
      
      for (int i = 0; i < 2; i++)
        for (int j = 0; j < 5; j++)
          cout <<"x["<<i<<"]["<<j<<"] = " <<x[i][j] <<endl;
          
      return(0);
    }
    
    
    /*
     Output:
     
     x[0][0] = 1
     x[0][1] = 2
     x[0][2] = 3
     x[0][3] = 4
     x[0][4] = 5
     x[1][0] = 2
     x[1][1] = 4
     x[1][2] = 6
     x[1][3] = 8
     x[1][4] = 10
    
    */
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Mutli dimensional Array question.
    By fatdunky in forum C Programming
    Replies: 6
    Last Post: 02-22-2006, 07:07 PM
  2. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 05:15 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM
  5. array question?
    By correlcj in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2002, 06:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21