Hello,
We have the following code fragment:
char tab[2][3] = {'1', '2', '\0', '3', '4', '\0'};
printf("%s\n", tab);
And I don't understand why we don't get an error / warning in the call to I DO get a warning but not an error, and the program runs fine. It prints 'printf
.12
'.
printf
is expecting an argument of type char *
, i.e. a pointer to char
. So if I declared char arr[3]
, then arr
is an address of a memory unit which contains a char
, so if I called printf
with it, it would decay to pointer to char, i.e. char *
.
Analogously, tab
is an address of a memory unit that contains the type array of 3 char's which is in turn, an address of memory unit contains char
, so tab
will decay to char **
, and it should be a problem, since printf
is expecting a char *
.
Can someone explain this issue?
Addendum:
The warning I get is:
a.c:6: warning: char format, different type arg (arg 2)