Initializing entire array with memset
问题 I have initialised the entire array with value 1 but the output is showing some garbage value. But this program works correctly if i use 0 or -1 in place of 1. So are there some restrictions on what type of values can be initialised using memset. int main(){ int a[100]; memset(a,1,sizeof(a)); cout<<a[5]<<endl; return 0; } 回答1: memset, as the other say, sets every byte of the array at the specified value. The reason this works with 0 and -1 is because both use the same repeating pattern on