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;
}
sizeof(a)does, and then you should figure out what is the type of the third argument ofmemset(). This should clear it up. PS. Don't do this in C++, it is unnecessary, and as you see, wrong.std::fill(std::begin(a), std::end(a), 1);