So, how good are you? ;) (C/C++)
-
Here's a test for all you C/C++ programmers: anything strange in the following code fragment? (Try not to compile it, okay? Just see if you can spot anything strange!) char ch; for (ch = 0;ch <= 255;ch++) std::cout << ch;
-
Here's a test for all you C/C++ programmers: anything strange in the following code fragment? (Try not to compile it, okay? Just see if you can spot anything strange!) char ch; for (ch = 0;ch <= 255;ch++) std::cout << ch;
-
Here's a test for all you C/C++ programmers: anything strange in the following code fragment? (Try not to compile it, okay? Just see if you can spot anything strange!) char ch; for (ch = 0;ch <= 255;ch++) std::cout << ch;
Besides the first 31 characters containing control and unprintable characters, I would say the problem would be that 255 would never be reached. char can contain values -128 through to 127. As soon as the eighth bit was filled it would become a negative number. So how did I go? Am I as good as I tell my wife I am or what !!! Michael Martin Pegasystems Pty Ltd Australia martm@pegasystems.com +61 413-004-018
-
Besides the first 31 characters containing control and unprintable characters, I would say the problem would be that 255 would never be reached. char can contain values -128 through to 127. As soon as the eighth bit was filled it would become a negative number. So how did I go? Am I as good as I tell my wife I am or what !!! Michael Martin Pegasystems Pty Ltd Australia martm@pegasystems.com +61 413-004-018
-
There is no opening and closing brackets for the cout instruction?:confused: This works with the microsoft compiler but not with C++ Builder. (Am I wrong? - I really didn't cheat):-D
oops, wrong answer, Frederick! See the other posts!
-
Besides the first 31 characters containing control and unprintable characters, I would say the problem would be that 255 would never be reached. char can contain values -128 through to 127. As soon as the eighth bit was filled it would become a negative number. So how did I go? Am I as good as I tell my wife I am or what !!! Michael Martin Pegasystems Pty Ltd Australia martm@pegasystems.com +61 413-004-018
Bingo! I'd say your wife is lucky. On the other hand, you could be a nerd...:)
-
Even with unsigned char, you would have trouble because the loop condition is for i <= 255, so even an unsigned char would roll over to 0 without terminating the loop.
Not true. unsigned char can hold a value of 255. Formula is 2n -1 (where n is the number of bits in the data type)for unsigned values. In this case it is 28 - 1 = 255. Michael Martin Pegasystems Pty Ltd Australia martm@pegasystems.com +61 413-004-018
-
Not true. unsigned char can hold a value of 255. Formula is 2n -1 (where n is the number of bits in the data type)for unsigned values. In this case it is 28 - 1 = 255. Michael Martin Pegasystems Pty Ltd Australia martm@pegasystems.com +61 413-004-018
Of course unsigned char can hold 255, but to terminate this loop you need 256, look again on condition: ch<=255; Do you feel that you still good? :)