Basic C++ error. Run-Time Check Failure #2 - Stack around the variable 'matrix' was corrupted

user3475761

I am just starting to make a matrix calculator and am frustrated to have run into problems so early. I am making a 3x3 Matrix calculator and am having problems entering values to the array, it runs fine as far as I can tell until "cin matrix[2][2];" when I get an error "Run-Time Check Failure #2 - Stack around the variable 'matrix' was corrupted." My guess would be I am entering outside the array and so it is undefined but I cannot see how I am, thanks for any help.

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
   double matrix[2][2];

   for(int i=0;i<=2;i++)
{
    for(int j=0;j<=2;j++)
    {
        cout<<"Enter value: ["<<i+1<<"]["<<j+1<<"] of your 3x3 vector.\n";
        cin>>matrix[i][j];
    }
}
   cout<<matrix[1][2];

  cin.get();

  return 0;
}
Gaurav Sehgal

the indexing of arrays in c++(and in fact in many programming languages)begins from 0.But when you specify the size you don't count from 0.So it should be-

double matrix[3][3];

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Run-Time Check Failure #2 - Stack around the variable '' was corrupted

From Dev

Run-Time Check Failure #2 - Stack around the variable '...' was corrupted

From Dev

C++ - Run-Time Check Failure #2 - Stack around variable 'sourceCount' was corrupted

From Dev

C++ - Run-Time Check Failure #2 - Stack around variable 'sourceCount' was corrupted

From Dev

Why am I getting Run-Time Check Failure #2 - Stack around the variable 'x' was corrupted?

From Java

Run-Time Check Failure #2 - Stack around the variable 'sortObject' was corrupted. how to fix?

From Dev

Run-Time Check Failure #2 - Stack around the variable 'foo' was corrupted

From Dev

Run-Time Check Failure #2 - Stack around the variable 'd' was corrupted

From Dev

Why am I getting Run-Time Check Failure #2 - Stack around the variable 'x' was corrupted?

From Dev

Run-Time Check Failure #2 - Stack around the variable 'char' was corrupted

From Dev

Run-time Check Failure #2 - Stack around the variable "primes" was corrupted

From Dev

Run-Time Check Failure #2 - Stack around the variable 'result' was corrupted

From Dev

Run-Time Check Failure #2 - Stack around the variable 'obj' was corrupted

From Dev

Run-Time Check Failure #2 - Stack around the variable 'numberchoices' was corrupted

From Dev

RunTime Check Failure #2 - Stack around the variable "tab" was corrupted

From Dev

C: Error with stack around the variable 's' was corrupted

From Dev

"Stack around the variable was corrupted" error

From Dev

"Stack around the variable was corrupted" error

From Dev

Stack around variable was corrupted - C

From Dev

Getting error: Stack around the variable was corrupted

From Dev

Stack around the variable was corrupted

From Dev

Stack around variable was corrupted

From Dev

Stack around variable was corrupted

From Dev

C - Stack around the variable 'name' was corrupted

From Dev

Stack around the variable is corrupted c++

From Dev

stack around the variable...was corrupted

From Dev

Stack around variable 'x' was corrupted

From Dev

Stack around the variable 'sortArray' was corrupted

From Dev

stack around the variable "variable name" was corrupted C++

Related Related

  1. 1

    Run-Time Check Failure #2 - Stack around the variable '' was corrupted

  2. 2

    Run-Time Check Failure #2 - Stack around the variable '...' was corrupted

  3. 3

    C++ - Run-Time Check Failure #2 - Stack around variable 'sourceCount' was corrupted

  4. 4

    C++ - Run-Time Check Failure #2 - Stack around variable 'sourceCount' was corrupted

  5. 5

    Why am I getting Run-Time Check Failure #2 - Stack around the variable 'x' was corrupted?

  6. 6

    Run-Time Check Failure #2 - Stack around the variable 'sortObject' was corrupted. how to fix?

  7. 7

    Run-Time Check Failure #2 - Stack around the variable 'foo' was corrupted

  8. 8

    Run-Time Check Failure #2 - Stack around the variable 'd' was corrupted

  9. 9

    Why am I getting Run-Time Check Failure #2 - Stack around the variable 'x' was corrupted?

  10. 10

    Run-Time Check Failure #2 - Stack around the variable 'char' was corrupted

  11. 11

    Run-time Check Failure #2 - Stack around the variable "primes" was corrupted

  12. 12

    Run-Time Check Failure #2 - Stack around the variable 'result' was corrupted

  13. 13

    Run-Time Check Failure #2 - Stack around the variable 'obj' was corrupted

  14. 14

    Run-Time Check Failure #2 - Stack around the variable 'numberchoices' was corrupted

  15. 15

    RunTime Check Failure #2 - Stack around the variable "tab" was corrupted

  16. 16

    C: Error with stack around the variable 's' was corrupted

  17. 17

    "Stack around the variable was corrupted" error

  18. 18

    "Stack around the variable was corrupted" error

  19. 19

    Stack around variable was corrupted - C

  20. 20

    Getting error: Stack around the variable was corrupted

  21. 21

    Stack around the variable was corrupted

  22. 22

    Stack around variable was corrupted

  23. 23

    Stack around variable was corrupted

  24. 24

    C - Stack around the variable 'name' was corrupted

  25. 25

    Stack around the variable is corrupted c++

  26. 26

    stack around the variable...was corrupted

  27. 27

    Stack around variable 'x' was corrupted

  28. 28

    Stack around the variable 'sortArray' was corrupted

  29. 29

    stack around the variable "variable name" was corrupted C++

HotTag

Archive