Home > Back-end >  Int * * p output two-dimensional array error
Int * * p output two-dimensional array error

Time:10-01

Void main (void)
{
Int * * p;
Int a [2] [3]={{1, 2, 3}, {21,22,23}};
for(int i=0; I<2; I++)
{
P=new int [I] [3].
For (int j=0; J<3; J++)
{
P=a [I] [j] [I] [j];
Cout<& lt;" P [" & lt; & lt; i<& lt; "]="& lt;

}
}
}

Why remove cout<& lt;" P [" & lt; & lt; i<& lt; "]="& lt;

CodePudding user response:

Void main (void) {
Int * * p;
Int a [2] [3]={{1, 2, 3}, {21, 22, 23}};

P=new int * [2];

for (int i=0; I & lt; 2; I++) {
P=new int [I] [3].
For (int j=0; J & lt; 3; J++) {
P=a [I] [j] [I] [j];
Cout & lt; <"P [& lt; & lt;" I & lt; & lt; "]="& lt;

}
}
}

CodePudding user response:

 
Int main (int arg c, char * argv [])
{
Int * p [3];//change the p * * to * p [3], which define a dimension
Int a [2] [3]={{1, 2, 3}, {21,22,23}};

for(int i=0; I<2; I++)
{
P=new [I] [3] (int *);
For (int j=0; J<3; J++)
{
P=a [I] [I];
Cout<& lt;" P [" & lt; & lt; i<& lt; "]="& lt;

}
}
}

CodePudding user response:

 
Void __fastcall TForm1: : Button2Click (TObject * Sender)
{
Int * p [3];
Int a [2] [3]={{1, 2, 3}, {21,22,23}};

for(int i=0; I<2; I++)
{
P=new int [I] [3].
For (int j=0; J<3; J++)
{
P=a [I] [j] [I] [j];
ShowMessage (p [I] [j]);
}
}
}
  • Related