Learning C, Number Representations
In C, the code in the following if statement is evaluated to true:
Why is that?
Because of how numbers are represented in C.
- 38 is just 38
- '&' is a char, also represented by the number 38
- 046 is an octal number, representing 38
- 0x26 is hexadecimal for 38
So that's why all following snippets print something.
Now, I shoud have known this by heart by now. But software development grows in you organically, not at once after taking a course at the university.
Anyways, great stuff from K&R, n'est pas?