vendredi 1 mars 2019

Can we assign a value inside the if statement?

#include <stdio.h>
void main()
{
    int x = 0;
    if (x = 0)
      printf("It's zero\n");
    else
      printf("It's not zero\n");
}

Why is the statement if (x = 0) not an error? Can we assign a value like that in an if statement? Why is it not generating an error and why is the else statement getting executed?

Aucun commentaire:

Enregistrer un commentaire