Thread: array first time

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    24

    array first time

    when I run the below code, only the indice[3][4] output it displays weird. Everything else fine.

    Code:
    #include <iostream>
    #include <conio.h>
    using namespace std;
    
    int main ()
    {
    int i, j;
    int multi[4][4];
    for (i=0; i<5; i++)
    {
        for(j=0;j<5; j++)
        {
            multi[i][j] = i*j;
             cout << "[" << i << "][" << j << "]=" << multi[i][j] << "\t";
        }
    }
    
    
    
    
    
         cin.get();
    
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You have an array out of bounds error. You should either change the loop conditions to i < 4 and j < 4, or change to have a 5 by 5 array.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-17-2013, 11:32 PM
  2. Replies: 2
    Last Post: 04-17-2013, 12:25 AM
  3. it is my first time using C PRO(array) help!
    By oscar429 in forum C Programming
    Replies: 2
    Last Post: 11-29-2012, 09:54 PM
  4. qsot array of Time objects - help
    By plaster in forum C++ Programming
    Replies: 7
    Last Post: 03-05-2012, 02:28 PM
  5. Run-time error allocating 3-D array
    By OceanDesigner in forum C++ Programming
    Replies: 2
    Last Post: 10-22-2005, 02:02 AM