c - Fast method to initialize my array -


i have array of int , have initialize array value -1. use loop:

int i; int myarray[10];  for(i = 0; < 10; i++)     myarray[i] = -1; 

there faster ways?

the quickest way know value -1 (or 0) memset:

int v[10]; memset(v, -1, 10 * sizeof(int)); 

anyway can optimize loop in way:

int i; for(i = 10; i--;)     v[i] = -1; 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

wcf binding - How to create a wsdl file for a WCF service library? -