Actually your k=50
with a single =
is an assignment operator; since it appears in a list of arguments, the order of evaluation of arguments is undefined, and you get stuck by undefined behavior.
The compiler is free to pass (k>40)
before or after doing k=50
BTW, with GCC version 4.9 on Debian/Sid, when compiling your code with
gcc -Wall danglingcruze.c -o danglingcruze
I am warned by the compiler:
danglingcruze.c:2:1: warning: return type defaults to ‘int’ [-Wreturn-type]
main(){
^
danglingcruze.c: In function ‘main’:
danglingcruze.c:5:37: warning: operation on ‘k’ may be undefined [-Wsequence-point]
printf("%d %d %d %d", (k==35), k=50, (k>40), x); // gives output => 0 50 0 1
^
danglingcruze.c:5:37: warning: operation on ‘k’ may be undefined [-Wsequence-point]
danglingcruze.c:6:5: warning: format ‘%s’ expects argument of type ‘char *’,
but argument 2 has type ‘int’ [-Wformat=]
printf("\n%s",k==35); // gives output => (null)
^