[NSRCA-discussion] Chapter-12 computer science.
Matthew Frederick
mjfrederick at cox.net
Tue Jul 3 21:37:42 AKDT 2007
Darnit... I just realized I just typed something that was incorrect in my
previous posts... Yes, because of the way it was written it would return 256
if it was an integer (or double or whichever numeric data type you chose to
give it). I could have sworn adding 1 to a char would move it to the next
ASCII character though. As far as I remember a char is only one character...
I thought a string (a char array) was required to store more than one digit
or character. Anywho... I've had enough, my brain hurts, it's the 4th and I
just wanna enjoy the day off...
Matt
----- Original Message -----
From: "Duane Beck" <duane.e.beck at comcast.net>
To: "NSRCA Mailing List" <nsrca-discussion at lists.nsrca.org>
Sent: Wednesday, July 04, 2007 12:16 AM
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