I ran into this code:
char str[600];
scanf("%s", &str);
Of course, this emits this warning:
a.c:6:17: warning: format specifies type 'char *' but the argument has type
'char (*)[600]' [-Wformat]
scanf("%s", &str);
~~ ^~~~~~~
I know that the correct way is to remove the &
and type scanf("%s", str)
instead. But it does work, so my question is if this could cause any problems. Is it undefined behavior? When I switched str
to a pointer instead of an array it (obviously) did not work. But can this cause any problem when using an array?