I have an array of int and i have to initialize this array with the value -1. For now i use this loop:
int i;
int myArray[10];
for(i = 0; i < 10; i++)
myArray[i] = -1;
There are faster ways?
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.
The quickest way I know for the value
-1(or0) is memset:Anyway you can optimize the loop in this way: