structs and 2d arrays :P

This is a discussion on structs and 2d arrays :P within the C++ Programming forums, part of the General Programming Boards category; can anyone show me an example on how to do this...

  1. #1
    Unregistered
    Guest

    structs and 2d arrays :P

    can anyone show me an example on how to do this

  2. #2
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    struct SomeStruct // example of a struct...
    {
    int SomeInt;
    };



    int Array2D[20][3]; // example of a 2d array

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    or, if you want a 2D array inside a struct you'd go:
    PHP Code:
    struct 2DArray
    {
       
    int Array[2][2];
    }; 
    and in main()
    PHP Code:
    2DArray Structure;

    Structure.Array[0][0] = '1';
    Structure.Array[0][1] = '2';

    Structure.Array[1][1] = '3';
    Structure.Array[1][0] = '4'
    something like that

  4. #4
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    And of course a 2d array of a struct:

    Code:
    struct Thing
    {
       int ThingInt;
       long ThingLong;
    }
    
    Thing myThing[2][2];
    
    myThing[0][0].ThingInt=2;
    myThing[0][0].ThingLong=65535;
    myThing[0][1].ThingInt=4;
    myThing[0][1].ThingLong=64333;
    myThing[1][0].ThingInt=3;
    myThing[1][0].ThingLong=34543;
    myThing[1][1].ThingInt=6;
    myThing[1][1].ThingLong=23456;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic 2d array
    By Mithoric in forum C++ Programming
    Replies: 8
    Last Post: 12-29-2003, 08:19 AM
  2. 2d Array access by other classes
    By deaths_seraphim in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2001, 08:05 AM

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