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
Post a Comment