07-26-2023, 07:09 AM
Assigning a value using = instead of comparing with == in conditional statements.
// Incorrect
int x = 5;
if (x = 10) {
printf("x is 10\n");
}
// Correct
int x = 5;
if (x == 10) {
printf("x is 10\n");
}
// Incorrect
int x = 5;
if (x = 10) {
printf("x is 10\n");
}
// Correct
int x = 5;
if (x == 10) {
printf("x is 10\n");
}