-3

See the following code:

int i={
          printf("c" "++")
       };

it prints c++ and returns 3 to i. how it is assigning 3 to i? need explanation!

Thomas Dickey
  • 47,166
  • 7
  • 60
  • 95
Prakhar Verma
  • 309
  • 1
  • 2
  • 10

1 Answers1

3

printf returns the number of bytes written to stdout. "c++" is exactly three bytes long (not counting the null-terminator).

By the way, you really don't need to use the curly braces, you can simply do int i=printf("c" "++");.

ForceBru
  • 41,233
  • 10
  • 61
  • 89
  • @chux, __that's why__ I'm not counting it (there is one in the string itself, but it isn't printed, certainly) – ForceBru Sep 14 '15 at 11:25