dimanche 31 janvier 2021

Chaining assignment in an if condition

Hi just wondering if you use a chained assigment in an if condition, would the leftmost variable be used to check the if condition

like a=b=c , its a thats ultimetly checked and not b or c

#include <stdio.h>

 int main()
 {
  int a, b, c =0;
 
  // does this reduce to a == 100 and the variables b or c are not checked if they are == to 100 but simply assigned the value of 100 ? 
  if( (a = b = c = 100) == 100)
     printf( "a is 100 \n");

   
 return 0;
}

Aucun commentaire:

Enregistrer un commentaire