Here is one not-so-common way of initializing the pointer:
int *p = (int[10]){[1]=1};
Here, pointer point to compound literals.
#include <stdio.h>
int main(void)
{
int *p = (int[10]){[1]=1};
printf("%d\n", p[1]);
}
Output:
1
This program is compiled and run fine in G++ compiler.
So,
Is it the correct way to initializing a pointer to compound literals? or
Is it undefined behaviour initialize pointer to compound literals?