Home > Back-end >  For help on int arr [m] [n] [2] variable-length array instead of int (* * arr) [2] program how to mo
For help on int arr [m] [n] [2] variable-length array instead of int (* * arr) [2] program how to mo

Time:10-15

The original program BBS is a classmate of matrix printing problems, I wrote a enhanced version, will only to solve with variable length arrays, would like to know how to solve if using pointer
 # include & lt; stdio.h> 

Int main ()
{
Unsigned int a=0, b=0;
Printf (" Introduzca 2 numero (1 y ~, entre non-numeric exit) : ");
While (the scanf (" % d % d ", & amp; A, & amp; B))
{
Int c [a] [b] [2]; Do not use variable-length array//here, but using a pointer, the back of the memory for how to deal with
for(int i=0; ifor(int j=0; J{
C [I] [j] [0]=I;
C [I] [j] [1]=j;
}
for(int i=0; ifor(int j=0; JPrintf (" [% d % d], c [I] [j] [0], c [I] [j] [1]).
Printf (" Introduzca 2 numero (1 y ~, entre non-numeric exit) : ");
}
return 0;
}


Why I use other function call won't get the right running
 # include & lt; stdio.h> 
Void primatrix (int pa, int, pb, PC/pa int [pb] [2]).
Aa, int ab void assmatrix (int, int ac (aa) [ab] [2]).
Int main ()
{
Unsigned int a=0, b=0;
Printf (" Introduzca 2 numero (1 y ~, entre non-numeric exit) : ");
While (the scanf (" % d % d ", & amp; A, & amp; B))
{
Int c [a] [b] [2];

Assmatrix (a, b, c [a] [b] [2]).
Primatrix (a, b, c [a] [b] [2]).
Printf (" Introduzca 2 numero (1 y ~, entre non-numeric exit) : ");
}
return 0;
}
Void primatrix (int pa, int, pb, PC/pa int [pb] [2])
{
for(int i=0; ifor(int j=0; JPrintf (" [] % d % d ", PC [I] [j] [0], PC [I] [j] [1]).
}
Aa, int ab void assmatrix (int, int ac (aa) [ab] [2])
{
for(int i=0; ifor(int j=0; J{
Ac [I] [j] [0]=I;
Ac [I] [j] [1]=j;
}
}

CodePudding user response:

The first question about the call is not successful, his thought about the possible problems, after the test has been solved,
 # include & lt; stdio.h> 
Void primatrix (int pa, int, pb, PC/pa int [pb] [2]).
Aa, int ab void assmatrix (int, int ac (aa) [ab] [2]).
Int main ()
{
Unsigned int a=0, b=0;
Printf (" Introduzca 2 numero (1 y ~, entre non-numeric exit) : ");
While (the scanf (" % d % d ", & amp; A, & amp; B))
{
Int c [a] [b] [2];
Assmatrix (a, b, c);//before parameters transfer form is wrong, when used in declaration and is not the same as
Primatrix (a, b, c);//same as above
Printf (" Introduzca 2 numero (1 y ~, entre non-numeric exit) : ");
}
return 0;
}
  • Related