#include <assert.h>
#include <stdio.h>
#define LEN 4
int main()
{
int i = 6;
printf("%d",i); // works
char str[LEN] = {'%', 'd', 0};
printf("%s",str); // crash
printf(str, i); // would also crash
}
The crash also occurs without the initializer (using some other way to set up str).
The crash does not occur if str is changed to static storage duration (I've tried both using the static keyword and moving it outside the function).