- 正无穷
memset(a,127,sizeof(a));
- 负无穷
memset(a,128,sizeof(a));
- 正无穷的一半
memset(a,60,sizeof(a));
memset(a,0x3f,sizeof(a));
- 赋值0
memset(a,0,sizeof(a));
- 赋值-1
memset(a,-1,sizeof(a));
- 二维数组
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int a[N][N];
int main() {
int cnt = 0;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
a[i][j] = ++cnt;
memset(a, 0, sizeof(a));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++)
cout << a[i][j] << ' ';
cout << endl;
}
return 0;
}