Thread: What is Multi Dimensional Array?

  1. #1
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112

    Post What is Multi Dimensional Array?

    Read the code below,
    Code:
    int main()
    {int a[3][3],i,j;
     {for(i=0;i<3;i++)
      for(j=0;j<3;j++)
      a[i][j] = 0;}
      printf("a[i][j] =%d\n",a[i][j]);
      return EXIT_SUCCESS;}
    i find it on c ebooks for android phone,
    its called multi dimensional array, but when i make a trial and error program
    the result of a[i][j] = 2293576
    the result was syntac error right?
    i didnt get was the multi dimensional array mean,

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Of course! There is a logical error on this code.

    What is the values of i and j when you reach the printf ?

    Then think what element of the array(if any) these values represent.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    yeahh i already figured it out,
    when i am using printf to i and j,
    it prints out 3 number,
    but i didnt get multi dimensional array things from my ebooks says,
    and why a didnt get any values?

  4. #4
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Let me rephrase the question.

    If I want to print the left top element of a 2D array, I would do
    Code:
    i = 0;
    j = 0;
    printf("a[i][j] =%d\n",a[i][j]);
    So this code would print me the a[0][0] element.

    In the code you have in the first example, in which element is the a[i][j]?

    I think that way you really learn to debug, so please don't throw away the answer (for the other members).
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by loserone+_+ View Post
    Read the code below,
    Now fixed:
    Code:
    int main()
    {  int a[3][3],i,j;
      
       for(i=0;i<3;i++) {
          for(j=0;j<3;j++) {
             a[i][j] = 0;
             
          }
       }
       return EXIT_SUCCESS;
    }
    i find it on c ebooks for android phone,
    its called multi dimensional array, but when i make a trial and error program
    The result was syntac error right?
    i didnt get was the multi dimensional array mean,
    Yes. It had an error. Now, where should that print statement go?

    A one dimensional array has length - like one line of text.

    A two dimensional array has length and width - like a table on a spreadsheet, or a page of text.

    A three dimensional array has length, width, and depth (or height) like several pages of text in a notebook, pad, or book.
    Last edited by Adak; 01-29-2013 at 08:31 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multi Dimensional Array
    By johnmackin in forum C Programming
    Replies: 0
    Last Post: 06-13-2012, 06:45 PM
  2. Multi dimensional array
    By $l4xklynx in forum C Programming
    Replies: 7
    Last Post: 01-03-2009, 03:56 AM
  3. multi-dimensional array
    By shuo in forum C++ Programming
    Replies: 4
    Last Post: 06-16-2008, 01:03 AM
  4. Multi dimensional array
    By big146 in forum C++ Programming
    Replies: 4
    Last Post: 06-14-2004, 05:03 PM
  5. multi-dimensional array
    By mcorn in forum C Programming
    Replies: 2
    Last Post: 08-04-2002, 09:14 AM

Tags for this Thread