jeudi 15 octobre 2020

Assignment operator works fine as a condition in if Statement in C programs [duplicate]

I am aware that when a non zero value is provided as a condition in an if statement, the condition is evaluated to be true.

Yet, I'm wondering how an assignment(=) is evaluated to be true here, instead of a comparison(==), and runs without any errors in the below C program.

int main(){
int a, b =5;

if(a=10) {
   ("This works");
}

if(b=1){
   ("This works too");
} }

Aucun commentaire:

Enregistrer un commentaire