This simple code is what I would expect:
#include <stdio.h>
int main()
{
char input[20];
printf("enter a string: ");
scanf("%[^\n]s", input);
printf("input: %s\n", input);
}
where input
is (char*)[20]
. But then why can I pass this:
#include <stdio.h>
int main()
{
char input[20];
printf("enter a string: ");
scanf("%[^\n]s", &input);
printf("input: %s\n", input);
}
and it still compiles and runs? The argument &input
passed should be (char**)[20]
which should not be correct, yet it runs. Why?