comments[i].length() return an unsigned integral type at least as large as
unsigned int, then
k will be promoted to the same unsigned type, and the rules of modular addition will apply.
As an example, this means that
1 < 2 - 3 is true, because
2 - 3 wraps around in modular arithmetic, becoming a very large number.
If you're interested, this behavior is specified in section 3.9.1 of the Standard, which includes the rule:
Unsigned integers shall obey the laws of arithmetic modulo 2n where n is the number of bits in the value representation of that particular size of integer.
And a footnote concerning the implications:
48 This implies that unsigned arithmetic does not overflow because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting unsigned integer type.
Mathematicians know this type of arithmetic as the algebra of Galois fields. In C++, it's used for unsigned integral types. Other types don't use modular arithmetic, but they also don't use normal grade-school arithmetic (formally, the algebra of real numbers), because normal arithmetic requires a dense uncountable set of numbers, and a computer of finite size can't represent members of an infinite set.
Thanks to Oliver for pointing out my mistake. GF(2)^n does govern the bitwise operations and a whole bunch of other common calculations done in computer software, such as CRC. But it doesn't describe unsigned arithmetic of more than 1 bit, since polynomials on Galois fields don't "carry".