Thread: two dimensional arrays

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    255

    two dimensional arrays

    i have a descet idea on one dimensional arrays but two dimensional arrays blew me out went way over my head so if anyone can clear up for me what they do and there purpose and litle sample to start with id appreciate it as i was trying to skip over that section in my book and go back to it but my book keeps using it so i figured id see if anyone can help me out here thanx bye
    hooch

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Just think of it as a rectangular grid.

    int i[3][3];

    3 elements across x 3 elements down.
    [][][]
    [][][]
    [][][]

    So if you did this:
    Code:
    int i[3][3];
    
    i[0][0]=1;
    i[0][1]=2;
    i[0][2]=3;
    
    i[1][0]=4;
    i[1][1]=5;
    i[1][2]=6;
    
    i[2][0]=7;
    i[2][1]=8;
    i[2][2]=9;
    You could imagine it like this:
    [1][2][3]
    [4][5][6]
    [7][8][9]

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    so would this be good forlike making charts on output or what?
    hooch

  4. #4
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    That is one way to use them. For example, tic tac toe could use one for knowing where the X's and O's are.

  5. #5
    In The Light
    Join Date
    Oct 2001
    Posts
    598
    howdy, this is a simple demo on how to initialize and access a 2 dimensional array.
    #include <iostream>
    #include <stdlib.h>

    Code:
    int main()
    {
      int stuff[5][5];//initialize a 6 by 6 array
      stuff[2][2] = 22;//place 22 in the location stuff[2][2]
      stuff[3][2] = 32;//place 32 in the location stuff[3][2]
      stuff[0][1] = 01;//place 01 in the location stuff[0][1]
    
      cout<<"location [2][2] contains: "<<stuff[2][2]<<endl;//obvious
      cout<<"location [3][2] contains: "<<stuff[3][2]<<endl;//obvious
      cout<<"location [0][1] contains: "<<stuff[0][1]<<endl;//obvious
      return 0;
    }
    regards
    M.R.
    I don't like you very much. Please post a lot less.
    Cheez
    *and then*
    No, I know you were joking. My point still stands.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointers and multi dimensional arrays
    By andrea72 in forum C++ Programming
    Replies: 5
    Last Post: 01-23-2007, 04:49 PM
  2. Dynamic two dimensional arrays
    By ThWolf in forum C++ Programming
    Replies: 14
    Last Post: 08-30-2006, 02:28 PM
  3. Two dimensional arrays
    By Masschino in forum C Programming
    Replies: 9
    Last Post: 05-18-2004, 08:17 PM
  4. dimensional arrays
    By ZakkWylde969 in forum C++ Programming
    Replies: 3
    Last Post: 08-04-2003, 04:49 PM
  5. Two dimensional arrays
    By Jax in forum C Programming
    Replies: 1
    Last Post: 11-07-2001, 12:53 PM