I am studying the memset function now, but all the examples are regarding to char array as following:
char a[100];
memset(a, 0, 100);
it will set every element in this char array to 0.
I wondered if memset can apply to int array or float array?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, it can apply to any memory buffer, but you must input the correct memory buffer size …
memsettreats any memory buffer as a series of bytes, so whether it’schar,int,float,double, etc, doesn’t really matter. Keep in mind though that it will not set multi-byte types to a specific non-zero value … for example:will not set each member of
ato the value 1 … rather it will set every byte in the memory buffer taken up byato1, which means every four-byteintwill be set to the value0x01010101, which is not the same as0x00000001