mardi 24 novembre 2020

why using the assignment operator instead of equal to operator works in the following situation?

You should have a condition which should evaluate to true or false in order for an if statement to work. I don't understand how p=fopen("test.txt", "r") part of the following code evaluates to true or false since it only contains an assignment operator = and not a == operator.

int main()
{
  FILE *p;
  if(p=fopen("test.txt","r"))
  {
      printf("yes\n");
  }
  else
    printf("no\n");
  return 0;```


Aucun commentaire:

Enregistrer un commentaire