Friday 22 March 2013

infinite loop example


    main()
{
    unsigned int i=10;
    while(i-->=0)
         printf("%u ",i);

}
Answer:
    10 9 8 7 6 5 4 3 2 1 0 65535 65534…..
Explanation:
Since i is an unsigned integer it can never become negative. So the expression i-- >=0  will always be true, leading to an infinite loop.  

Blog Author: Vijay Kumar

No comments:

Post a Comment