fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int i = (1,2,3,4,5);
  5. int j = {1,2,3,4,5};
  6. int k = *(&i+1);
  7. printf("(1,2,3,4,5) = %d\tthrows away values 1-4\n",i);
  8. printf("{1,2,3,4,5} = %d\ttries to initialise an array starting where our int is stored (nasty UB)\n",j);
  9. printf("Does the compiler limit initialisation to only the int? %s",k!=2?"yes":"no");
  10. return 0;
  11. }
  12.  
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
(1,2,3,4,5) = 5	throws away values 1-4
{1,2,3,4,5} = 1	tries to initialise an array starting where our int is stored (nasty UB)
Does the compiler limit initialisation to only the int? yes