Monday, January 18, 2010

Question I got

Through the week 1 studying, I learn that

int a;
a=printf("ABC");

will cause a equal 3. Then I am curise that if I use this new thing with char ,what the result will be. So I do a test

char a;
a=printf("ABC");

There is no suprise for the result. It prints ABC. But another question came to my mind. Why it prints ABC instead of just A? I remember that a char can only be stored the first income character and the rest will be eliminated,if it's not a array.

I am still attempting to figure out the reason.

1 comment:

  1. here is the reference of printf


    printf returns the total number of characters it has written.


    in your case, "ABC" was printed by you printf function, and you char a stores the return value of printf which is integer 3.


    if you call char a="ABC", that will be the same as you say. The char a stores the first income character and the rest will be eliminated.

    ReplyDelete