# Define X (3)
# Define y (5)
Int main (){
Int
D [x] [Y] = {1, 2, 3, 4, 5, 6, 7, 8 };/* I want to print the content of d */
}
Then, we generally write as follows:
# Define X (3)
# Define y (5)
Int main (){
Int
D [x] [Y] = {1, 2, 3, 4, 5, 6, 7, 8};/* I want to print the content of d */
/* This is the implementation solution in main */
Int I, J;
For (I = 0; I <= X-1; I ++ ){
For (j = 0; j <= Y-1; j ++ ){
Printf ("% d,", d [I] [J]);
}
Printf ("\ n ");
}
Return 0;
}
Because we may often need to print a two-dimensional array, we would like to write a function specifically to do this:
# Define X (3)
# Define y (5)
/* To print d [] [] at any time, I plan to write the following function to do this */
/* Note the writing of this function parameter. Can I change it to int d [] [] or Int d [x] [] or Int d [x] [Y?
Think about it. Why? */
Void show (Int d [] [5]){
Int I, J;
For (I = 0; I <= X-1; I ++ ){
For (j = 0; j <= Y-1; j ++ ){
Printf ("% d,", d [I] [J]);
}
Printf ("\ n ");
}
Return;
}
Int main (){
Int
D [x] [Y] = {1, 2, 3, 4, 5, 6, 7, 8 };
/* I want to print the content of d */
/* This is the implementation solution using functions */
Show (d );
Return 0;
}
Let's look at another form of description:
# Define X (3)
# Define y (5)
/* Further derivation, You know, professionalProgramYou always like to write pointer parameters in function parameters,
Instead of int d [] [Y.
So we have the followingCode. */
Void show (Int * d) {/* See!Here is a pointer Parameter*/
Int I, J;
For (I = 0; I <= X-1; I ++ ){
For (j = 0; j <= Y-1; j ++ ){
Printf ("% d ,",D [I * Y + J]);/* See!Does this statement profoundly reflect the relationship between pointers and array elements?*/
}
Printf ("\ n ");
}
Return;
}
Int main (){
Int
D [x] [Y] = {1, 2, 3, 4, 5, 6, 7, 8 };
/* I want to print the content of d */
/* This is the implementation solution in main */
Show (d );
Return 0;
}
So far, readers can understand the meaning of the above Code.
All the code in this article can be downloaded here.