Initialization of vectors

A vector type can be initialized by a vector literal, or any expression having the same vector type. For example:
vector unsigned int v1;
vector unsigned int v2 = (vector unsigned int)(10);
v1 = v2;
A vector type can also be initialized by an initializer list.

Vector initializer list syntax

Read syntax diagramSkip visual syntax diagramvector_type?identifier = (initializer_list){initializer_list} ;
An initializer list enclosed with parentheses must have the same number of value as the number of elements of the vector type. The number of values in a braced initializer list must be less than or equal to the number of elements of the vector type. Any uninitialized element will be initialized to zero.
The following examples show vector initialization using initializer lists:
vector unsigned int v1 = {1}; // initialize the first element (4 bytes) of v1 
                              // with 1 and the remaining 3 elments (12 bytes)
                              //	 with zeros 

vector unsigned int v2 = {1,2}; // initialize the first element (4 bytes) of v2
                                // with 1, the next element (4 bytes) with 2,
                                // and the remaining elements (8 bytes) with zeros

vector unsigned int v3 = {1,2,3,4}; // equivalent to the vector literal
                                    // (vector unsigned int) (1,2,3,4) 
Unlike vector literals, the values in the initializer list do not have to be constant expressions unless the initialized vector variable has static duration. Thus, the following code is valid:
int i=1;
int function() { return 2; }
int main()
{
   vector unsigned int v1 = {i, function()};
   return 0;
}