c - Why does printf(i) give 0 as output in this program? -
#include <stdio.h> int main() { int i=-1; !i; printf(i); }
output:
0
why output zero?
in code,
printf(i);
is invalid, because printf()
expects const char *
first argument, , you're passing int
. invokes undefined behaviour.
turn compiler warnings. basic level of warning turned on, should message along line
warning: passing argument 1 of ‘printf’ makes pointer integer without cast
solution: believe, wanted is
printf("%d\n", i);
Comments
Post a Comment