What is the problem in this code ? It shows memory dump error in runtime
#include<iostream>
using namespace std ;
int main()
{
int A[3][4] = {{3, 1, 8, 11}, {4, 12, 9, 10}, {7, 5, 2, 6}};
int **p = A;
P[1][2] = 99;
cout<<A[1][2] ;
}
Change your int **p = A[0][0]
to int *p = &A[0][0]
. In the next line, write the following *p = *((int*)p + 1 * NUM_OF_COLUMNS + 2) = 99;
, where NUM_OF_COLUMNS is the number 4, instead of the P[1][2] = 99;
. Correct the spelling of main as well as uppercase/lowercase of variables. Also add a return 0;
at the end since you have an int main()
and not a void.