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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -