| | |
Plz Solve this problem...
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2007
Posts: 5
Reputation:
Solved Threads: 0
Hi . i m new in c++ programming..plz help me in sorting out this problem.....
HOW THE VALUE OF "j" VARIES IN FOLLOWING PROBLEMS ? Plz Explain...
1. int i=10,j;
j= (i++) + (i++);
cout<<j;
2. int i=10,j;
j= (i++) + (++i);
cout<<j;
3. int i=10,j;
j= (++i) + (i++);
cout<<j;
4. int i=10,j;
j= (++i) + (++i);
cout<<j;
HOW THE VALUE OF "j" VARIES IN FOLLOWING PROBLEMS ? Plz Explain...
1. int i=10,j;
j= (i++) + (i++);
cout<<j;
2. int i=10,j;
j= (i++) + (++i);
cout<<j;
3. int i=10,j;
j= (++i) + (i++);
cout<<j;
4. int i=10,j;
j= (++i) + (++i);
cout<<j;
It's the order that the sums and increments are executed. In each expresion you listed there are different addition operations to be done and depending on what order you do them effects the result. i++/++i is shorthand for i = i + 1; If you place the ++ before the i (prefix) this is generally accepted as increment i *before* evaluating the expression, putting ++ after the i (postfix) means evaluate the expression first and increment i *afterwards*. Also placing things in parentheses generally means evaluate this part of the expression first, but I imagine they are only in this example for clarity (there's only so many +'s the human eye can take!)
•
•
•
•
But turbo C..compiler shows the value oj j in ...
The truth does not change according to our ability to stomach it.
1. j= (i++) + (i++);
Compiles to machine instructions in this order:
j = 10 + 10
i = 10 + 1
i = 11 + 1
2. and 3.
i = 10 + 1
J = 11 + 11
I = 11 + 1
4.
i = 10 + 1
i = 11 + 1
j = 12 + 12
Compiles to machine instructions in this order:
j = 10 + 10
i = 10 + 1
i = 11 + 1
2. and 3.
i = 10 + 1
J = 11 + 11
I = 11 + 1
4.
i = 10 + 1
i = 11 + 1
j = 12 + 12
But like everyone else points out it's kind of nonsense, because 1. why would you ever need to do that anyway? Obfuscation? other than that I can't think of anything. and 2. it's contrary to the standard.
Last edited by hollystyles; Aug 20th, 2007 at 10:33 am.
![]() |
Similar Threads
- plzz solve my problem (C++)
- plz tell me how to solve problem (JSP)
- friend plz help me to solve this problem (C++)
- plz help to solve this prob (ASP.NET)
- Anyway can help me to solve this problem??? (C++)
- plz help me to connect more than one table in the ms access database to the asp.net (ASP.NET)
- CDBException can't solve problem (ASP.NET)
- please help been at my pc for hours still cannot solve problem (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: splaying algorithm
- Next Thread: How to convert very long string to a double???
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets







The value of