I was looking at MIT assignments and found this statement below link problem 2.5) option B)
https://ocw.mit.edu/courses/6-087-practical-programming-in-c-january-iap-2010/63515d4218cf01ba460623cbe9dc3b5c_MIT6_087IAP10_assn02_sol.pdf
Now it says
Assume (x=0,y=0,alliszero=1). alliszero =(x=1) && (y=0);
they are just asking to find statement will give error or not.
And in solution they are saying
’=’ operator should be replaced with ’==’. The correct version is
alliszero =(x==1) && (y==0);
consider below program
#include <stdio.h>
void main()
{
int x =0 , y = 0 , alliszero =1;
alliszero = (x = 1) && (y = 0);
printf("%d",alliszero);
}
Now after I run this program then I am getting output as 0, But above they mentioned it as error, I am understanding that it might be one of the compiler dependent things then what is happening that doesn’t allow ‘=’ to work with ‘&&’ operator?
Bhargav Patil is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.