|
-
March 7th, 2011, 12:50 AM
#1
anomalous loop behavior
Hi. Im an economics undegrad who knows a bit of C and is baffled by something I tried out.
I was looking up C's data types. Im interested in unsigned char for a moment. Heres what I tried (forgive me if Im supposed to enclose code in some special enclosure, im unaware of it):
#include <stdio.h>
int main()
{
unsigned char i = 0;
for (i = (unsigned char) 0; i <= (unsigned char) 255; i++)
{
printf("%d\n", i);
};
return 0;
}
Since i can take values between 0 and 255, I expected this look to print 1 to 255 and then quit but strangely it goes into an infinite loop. The for loops condition is never being met even though it prints 255. This is strange and I guess someone who is in computer science or engineering could probably figure this out.
So why is it an infinite loop? If it helps, its being run on a linux Pent 4 machine
thx for help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|