We were discussing few of the assignment problems in our C class. Our instructor showed a simple printf statement.
int k = 1234567890;
printf("%5i",k);
He asked us what is the output for the above program. We all said the answer would be 12345, but we were told that the computer would print the entire numbers. (test this for yourself if you have any doubt). Computer didn't make any mistake here but we made the mistake of not knowing the correct functionality of %5i.
Even this had happened to me before where I assume this is the way it would work till I start coding. Once I start the coding process, a lot of new questions about my initial assumption would come, till I finally conclude I am wrong.
moral of the whole story is "Always try to test the assumptions before you conclude".
Saturday, October 21, 2006
Subscribe to:
Posts (Atom)