bharadwaj75's blog

By bharadwaj75, 10 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?
»
10 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.

»
10 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

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

scanf returns the number of read items.

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

1 means true

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

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

  • »
    »
    10 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