HumbleWorker <amardeep.developer@gmail.com> writes:
> On Aug 10, 9:57Â pm, James Kuyper <jameskuy...@verizon.net> wrote:
>> On 08/10/2011 12:51 PM, HumbleWorker wrote:
>>
>> > On Aug 10, 9:43 pm, tom st denis <t...@iahu.ca> wrote:
>> >> On Aug 6, 1:25 pm, HumbleWorker <amardeep.develo...@gmail.com> wrote:
>>
>> >> int main()
>> >> {
>> >> Â Â char *k = "abababababawhatever";
>> >> Â Â while(*k) numA += *k++ == 'a';
>> >> Â Â printf("Number of a's = %d\n", numA);
>> >> Â Â return 0;
>>
>> >> }
>>
>> >> :-)
>>
>> > Thanks ! Is it guaranteed that a logical true returns 1 ?
>>
>> All logical expressions in C indicate truth by having a result of 1.
>
> As we have know that any non-zero int evaluates to logical true, so
> vice-versa doesn't a compiler have the freedom to return anything non-
> zero ? Is there some standard that enforces that it should be 1 only ?
Yes, the C standard says so, e.g.:
6.5.13 Logical AND operator
The && operator shall yield 1 if both of its operands
compare unequal to 0; otherwise, it yields 0. The result has
type int.
....
6.5.14 Logical OR operator
The || operator shall yield 1 if either of its operands
compare unequal to 0; otherwise, it yields 0. The result has
type int.
--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa67f6aaa,0xaa9aa9f6,0x11f6},*p
=b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
2:{i++;if(i)break;else default:continue;if(0)case 1:putchar(a[i&15]);break;}}}