c - Why it doesn't print the "Hello"? -


this code compiles without errors why doesn't print "hello" after 5?

#include<stdio.h> #include<conio.h>  int main() {     int number = 5;     printf("%d",number,"hello");     getch(); } 

you need %s placeholder in addition %d placeholder. see below:

printf( "%d %s", number, "hello" ); 

... notice "hello" string literal (and hence null terminated string), meaning %s placeholder required if wish pass "hello" argument. since using string literal, suggest follows:

printf( "%d hello", number ); 

remark:

  1. the %d placeholder integer.
  2. the %s placeholder string (null terminated array of characters).

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -