It will work for ints by doing this:
int array[] = {1,2,3,4,5};
or that:
int *array = (int[]){1,2,3,4,5};
"string" tells the compiler all the information it needs (size, type) to create an instance of the string (or an array of bytes with the NULL terminator). Naked {} does not, unless you declare it as a composite literal . Adding ints[] tells the compiler that the initiated data is an array of integers.
As Nathan noted in the comments, there are subtle differences from the two statements.
First, defines an array of 5 ints on the stack. This array can be modified and live to the end of the function.
The second one, 1) defines an anonymous array of five ints on the stack 2) defines a pointer "array" for the first element of the anonymous array on the stack. The pointer should not be returned since the memory is on the stack. Furthermore, an array is not essentially const like a string literal.
EDIT: Replace the cast compound literal as indicated by the commenter.
James source share