function - Why the final result varies? -


when returning function, following coding style not seem work -

    return (int) minim(mid-l,r-mid) + (int) (mid+mid==n)?1:0; 

but following code working fine -

    int x = minim(mid-l,r-mid);     int y = (mid+mid==n)?1:0;     return x+y ;  

mid, l, r, n integers.

can please me understand why?

you need add parentheses '+' takes precedence on ternary operator '?:'

return (int) minim(mid-l,r-mid) + ((int) (mid+mid==n)?1:0); 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -