Confirm là không ai “rảnh” làm như thế này nhé.
#include <stdio.h>
int main()
{
int arr[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
// Print value using double for loop
for(int i = 0; i < 3; ++i) {
for(int j = 0; j < 3; ++j) {
printf("%d ", arr[i][j]);
}
printf("\n");
}
// Print address using double for loop
for(int i = 0; i < 3; ++i) {
for(int j = 0; j < 3; ++j) {
printf("%p ", &arr[i][j]);
}
printf("\n");
}
// Print value using single for loop
int *pa = arr;
for(int i = 0; i < 3*3; ++i) {
printf("%d ", *(pa+i));
if ( (i + 1) % 3 == 0 )
printf("\n");
}
// Print address using print address
for(int i = 0; i < 3*3; ++i) {
printf("%p ", pa+i);
if ( (i + 1) % 3 == 0 )
printf("\n");
}
}