No, you cannot set them to arbitrary values ββin one expression (unless this is done as part of the declaration).
You can do this with code, for example:
myArray[0] = 1; myArray[1] = 2; myArray[2] = 27; : myArray[99] = -7;
or (if there is a formula):
for (int i = 0; i < 100; i++) myArray[i] = i + 1;
Another possibility is to store some templates installed during the declaration and use them to initialize the array, for example:
static const int onceArr[] = { 0, 1, 2, 3, 4,..., 99}; static const int twiceArr[] = { 0, 2, 4, 6, 8,...,198}; : int myArray[7]; : memcpy (myArray, twiceArr, sizeof (myArray));
This has the advantage (most likely) faster and allows you to create smaller arrays than templates. I used this method in situations where I need to reinitialize the array quickly, but in a specific state (if all zeros were in the state, I would just use memset ).
You can even localize it using the initialization function:
void initMyArray (int *arr, size_t sz) { static const int template[] = {2, 3, 5, 7, 11, 13, 17, 19, 21, ..., 9973}; memcpy (arr, template, sz); } : int myArray[100]; initMyArray (myArray, sizeof(myArray));
A static array will (almost certainly) be created at compile time, so there will be no runtime overhead, and memcpy should be dazzlingly fast, probably faster than the 1,229 assignment operators, but itβs very less likely to type your role :-).