见大家不习惯用指针的形式,分享一种全用指针的写法吧,以供学习参考!
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
// write your code here......
int** p = new int* [n];
for (int i = 0; i < n; i++) {
*(p + i) = new int[n];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
*(*(p + i) + j) = i + j;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << *(*(p + i) + j) << ' ';
}
cout << endl;
}
return 0;
}