#include <stdio.h>
int main( void ) {
int i = ( 1 , 2 , 3 , 4 , 5 ) ;
int j = { 1 , 2 , 3 , 4 , 5 } ;
int k = * ( & i+ 1 ) ;
printf ( "(1,2,3,4,5) = %d\t throws away values 1-4\n " , i
) ; printf ( "{1,2,3,4,5} = %d\t tries to initialise an array starting where our int is stored (nasty UB)\n " , j
) ; printf ( "Does the compiler limit initialisation to only the int? %s" , k
!= 2 ? "yes" : "no" ) ; return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbih2b2lkKSB7CglpbnQgaSA9ICgxLDIsMyw0LDUpOwoJaW50IGogPSB7MSwyLDMsNCw1fTsKCWludCBrID0gKigmaSsxKTsKCXByaW50ZigiKDEsMiwzLDQsNSkgPSAlZFx0dGhyb3dzIGF3YXkgdmFsdWVzIDEtNFxuIixpKTsKCXByaW50ZigiezEsMiwzLDQsNX0gPSAlZFx0dHJpZXMgdG8gaW5pdGlhbGlzZSBhbiBhcnJheSBzdGFydGluZyB3aGVyZSBvdXIgaW50IGlzIHN0b3JlZCAobmFzdHkgVUIpXG4iLGopOwoJcHJpbnRmKCJEb2VzIHRoZSBjb21waWxlciBsaW1pdCBpbml0aWFsaXNhdGlvbiB0byBvbmx5IHRoZSBpbnQ/ICVzIixrIT0yPyJ5ZXMiOiJubyIpOwoJcmV0dXJuIDA7Cn0K
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