in some program i saw this line
i was wonderind what does this mean. hope you can help.Code:result += array[i] ? array[i] : 90;
in some program i saw this line
i was wonderind what does this mean. hope you can help.Code:result += array[i] ? array[i] : 90;
it's the same as:
Instead of doing all that C has the tertiary construct (three involved elements), (evaluate)?(if true): (if false).Code:if(array[i]) result+=array[i]; else result+=90;
Hope this helps
yes, thanks , it helps, but i'm still a little confused ,how should i understand
that means if value of array[i] is true ,right?Code:if(array[i])
Pretty much, just checking wether there is anything at array[i]. With "anything" meaning a value other than 0 (or if there is no element at that index)(which would be false), all other values are true(basically there is an element there)(so not only 1).
Last edited by coolman0stress; 08-14-2003 at 01:17 PM.
ok, thanks, i understand it now
>>(or if there is no element at that index)(which would be false)<<
There is always a value at that location (index), even if the value of i exceeds the array bounds.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Just conditional operator man. You can refer tutorials.
Saravanan.T.S.
Beginner.