Unexpected answer

The answer is ZERO 0. Why. Please explain
1
2
3
4
5
6
7
8
9
#include <stdio.h>

int main() {
    int p=100,q=5,r=50;
    int m;
    m = p == (q+r);
    printf("%d",m);
	return 0;
}
just remove the extra = should solve the problem.
It works out (in order):

q+r=55 (brackets sorted out first)

Tests whether 100==55 ... which it isn't, so evaluates as false.

Casts false to an integer to do the assignment (=) ... this is 0.


Exercise for the interested: change q+r to r+r and predict the result.
Thank you
Registered users can post here. Sign in or register to post.