c - Effect of the ||-operator on ++x -


#include<stdio.h> int main() {    int i=0, k=0, m;    m = ++i || ++k;    printf("%d, %d, %d\n", i, k, m);    return 0;  } 

returns

1,0,1 

why k = 0 , not 1? effect of ||-operator on ++k? thanks!

example: https://ideone.com/fjsbii

in || or , if first condition true, not check second condition.(it skip 2nd condition).

as

m = ++i || ++k; 

in condition after ++i, value of i become 1, first condition true, skip second condition. operation ++k not performed.
, hence k remain 0.

same if using && , , first condition false skip second condition. , result 0 (false).


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -