memset使用最详细细节
#include<bits/stdc++.h>
using namespace std;
int x[10];
signed main(){
//memset就是将数组每个下标都刷新成一个值
//memset(数组名,值,长度)
memset(x,0,sizeof(x));
for(int i = 0;i < 10;++i)
cout<<x[i]<<" ";
cout<<"\n";
//输出:0 0 0 0 0 0 0 0 0 0
//你真的了解怎么刷新了?
//那试试下面:
memset(x,1, sizeof(x));
for(int i = 0;i < 10;++i)
cout<<x[i]<<" ";
cout<<"\n";
//输出:16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009
//为什么不是1呢,而是16843009呢
//因为memset刷新是按照一个子节一个子节的刷新的
//即一个int被刷新后的二进制格式为:00000001 00000001 00000001 00000001即:16843009
//可以和最短路中把dis数组刷新为无穷大一样:3f3f3f3f
memset(x,0x3f,sizeof(x));
for(int i = 0;i < 10;++i)
cout<<x[i]<<" ";
cout<<"\n";
//输出:1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567
return 0;
}