I have a variable:
unsigned int* data = (unsigned int*)malloc(height * width)
I want to set same int to all array values.
I can’t use memset because it works with bytes.
How can i do that?
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.
Using C++:
If you need to pass the data to some legacy C function that expects a pointer, you can use
&data[0]or&data.front()to get a pointer to the contiguous data in a well-defined manner.If you absolutely insist on using pointers throughout (but you have no technical reason to do this, and I wouldn’t accept it in code review!), you can use
std::fillto fill the range: