[NSRCA-discussion] Chapter-12 computer science.
Ryan Smith
smaragdz at bellsouth.net
Tue Jul 3 21:25:02 AKDT 2007
Sooo...
Am I the only one that feels like a dunce? I think when I start classes
back, I'm going to take some more computer science classes.
Ryan
-----Original Message-----
From: nsrca-discussion-bounces at lists.nsrca.org
[mailto:nsrca-discussion-bounces at lists.nsrca.org] On Behalf Of Duane Beck
Sent: Wednesday, July 04, 2007 1:17 AM
To: NSRCA Mailing List
Subject: Re: [NSRCA-discussion] Chapter-12 computer science.
Depends on whether char basic type is 8-bit or larger. Most decent
compilers should issue a warning for comparing with an integer constant
out of range. Assuming default char type is 8-bit signed, when cnt is
127, cnt increments to -128 (by wrapping around adjacent two's
complement values) and the loop continues unterminated. If default char
type is 8-bit unsigned, it's still unterminated because after 255, cnt
will increment to 0. So, in both conditions, cnt is always less than
256. Otherwise, if char is larger (16-bit), foo returns 256.
Duane
Martin X. Moleski, SJ wrote:
> John Pavlick wrote:
>> OK, what does this do?
>
>> char foo(void)
>> {
>> char cnt, num;
>>
>> for(cnt = 0, num = 0; cnt < 256; cnt++)
>> {
>> num++;
>> }
>> return num;
>> }
>
>
> Initializes cnt and num to 0.
>
> Increments cnt and num from 0 to 255
> by passing through the for loop.
>
> Returns 255.
>
>
> Marty
> _______________________________________________
> NSRCA-discussion mailing list
> NSRCA-discussion at lists.nsrca.org
> http://lists.nsrca.org/mailman/listinfo/nsrca-discussion
>
_______________________________________________
NSRCA-discussion mailing list
NSRCA-discussion at lists.nsrca.org
http://lists.nsrca.org/mailman/listinfo/nsrca-discussion
More information about the NSRCA-discussion
mailing list