Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

bharadwaj75's blog

By bharadwaj75, 9 years ago, In English

printf("%d",scanf("%d",&a)) gives always 1 .Can any one tell what is the actual logic behind that?

  • Vote: I like it
  • +4
  • Vote: I do not like it

| Write comment?
»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

printf returns the number of items of the argument list successfully filled normally, in this case the return value is 1.

For more, view the section "Return Value" on this page.

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

It is not necessary 1, obviously the answer is the output of scanf(...), and if it works properly it is all the variables it could, read or -1 in eof

»
9 years ago, # |
  Vote: I like it +8 Vote: I do not like it

scanf returns the number of read items.

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

1 means true

  • »
    »
    9 years ago, # ^ |
      Vote: I like it +11 Vote: I do not like it

    No, it doesn't! 1 is the number of read elements.

  • »
    »
    9 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    If you write printf("%d",scanf("%d%d",&a,&b)) it will give 2