How to handle 'warning: comparison between signed and unsigned integer expressions' in c++?

Example:

int a = -5;
unsigned int b = 10;
if (a < b) {
    // ...
}

You're comparing signed and unsigned integers, which may produce unexpected results.

Solution:

Ensure the comparison is between variables of the same sign.


int a = -5;
int b = 10;
if (a < b) {
    // ...
}

Beginner's Guide to C++