How to find the value of z here
Int x = 5, y = 6, Z;
Z = x + + > (Z = - - Y)? Y + 2: ((x>z) ? x:y);
and why it prints 18 in the following programme-
Code:int main() { int x,y=10; x=y++ +--y; printf("%d",x); }
How to find the value of z here
Int x = 5, y = 6, Z;
Z = x + + > (Z = - - Y)? Y + 2: ((x>z) ? x:y);
and why it prints 18 in the following programme-
Code:int main() { int x,y=10; x=y++ +--y; printf("%d",x); }
Any single line of code with any single variable being incremented or decremented twice, is at best, unclear.
At worst, it's non-standard, compiler and/or machine dependent, and something best left for after hours fun, when the beer is flowing.
Don't waste your time messing with it, is my strong suggestion.
Well, first, you need a value for z (not Z, z) and then you can use the table here to guide you through the operation order.Code:Int x = 5, y = 6, Z; Z = x + + > (Z = - - Y)? Y + 2: ((x>z) ? x:y);
Edit, for that matter, you need a value for Y too. Variable names are case-sensitive, so if you're wanting to use just x, y and z, keep it all lower-case or upper-case.
In fact it is undefined, as someone pointed out last week. So this line:
is simply no good -- altho y-1=9 and 9+9 does equal 18, you should NOT use "--" or "++" more than once on the same variable in the same expression.Code:x=y++ +--y;
That other line is okay I think if you set the variable names correctly:
Code:z = x++ > (z = --y)? y+2 : (x>z)?x:y;
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
and why it prints 18 in the following programme-chk in the codeCode:int main() { int x,y=10; x=y++ +--y; printf("%d",x); }
here y is incremented after everything is done...while its decremented before anything is doneCode:x = y++ + --y
so the initial value of it is 10....then it becomes 9...(still its not incremented)..then it becomes 9+9 =x..after equating ..then the y value is incremented...so the answer is 18
No. Try reading what wiser people have already posted. You cannot use multiple ++ or -- operators (of combination thereof) on the same variable in the same statement and get defined results.
Also, if you want to be taken seriously, stop typing "y" and "chk" instead of "why" and "check". I'm not going to go through the whole dictionary for you. If you can't be bothered to type the whole word, don't bother typing at all! Some things are meant to be abbreviated. Those are not. If you're posting on a friggin' phone, go away until you can get to a real keyboard.
Quzah.
Hope is the first step on the road to disappointment.
Last edited by Obelisk; 10-19-2009 at 01:27 PM.
Not to mention the use of 'rite' instead of 'right', lack of punctuation (eg: missing periods and whatnot), not capitalizing sentences, and inconsistent use of spacing and certain punctuation (eg: '..', '...', and '....'). Not that it matters all that much, but it just looks sloppy and leaves a bad impression of your posts.