473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

evaluate it

hey people i was just testin this:
int i=5,j;
j=i++ + ++i;
cout<<j;
and then...

int i=5;
int j= i++ + ++i;
cout<<j;
both givin different results
y?
plz help

Jul 23 '05 #1
2 1065
as********@gmail.com wrote:
hey people i was just testin this:
int i=5,j;
j=i++ + ++i;
cout<<j;
and then...

int i=5;
int j= i++ + ++i;
cout<<j;
both givin different results
y?
plz help


Read the FAQ, section 39

V
Jul 23 '05 #2

<as********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
hey people i was just testin this:
int i=5,j;
j=i++ + ++i;
cout<<j;
and then...

int i=5;
int j= i++ + ++i;
cout<<j;
both givin different results
y?
plz help


The results are irrelevent. Since you are refering to the same variable in
that compound statement, the standard does not guarentee when, how or
whether the variable i gets incremented. In fact, the standard has a
requirement that the said variable be only modified once in between sequence
points.

Try:

#include <iostream>

int main()
{
int i = 5;

std::cout << "i = " << i << "\n";

int j(i++);

std::cout << "i = " << i << "\n";
std::cout << "j = " << j << "\n";

j += (++i);

std::cout << "i = " << i << "\n";
std::cout << "j = " << j << "\n";

return 0;
}

/*
i = 5
i = 6
j = 5
i = 7
j = 12
*/

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Spiegel | last post by:
Hi all, Is it possible to have an uncompiled C# expression evaluated at runtime? I'd like to store an expression within an XML file then evaluate it when the time comes, something like: ...
1
by: David Laub | last post by:
I have no problems running the following dynamic XPath evaluator form MSXSL: <msxsl:script implements-prefix="dyn" language="jscript"> evaluate(context, expression) { return...
2
by: dam_fool_2003 | last post by:
Friends, I come across a resent thread describes the differences between getc() vs fgetc(). There some body stated the sentence "evaluate its parameter more than once". I cannot understand the...
13
by: Zeng | last post by:
Hello, Please help!!! I've been stuck on this issue for months. I just wonder if there is a way to programmatically evaluate expression strings such as ( ( 3 + 5 ) / 2 ) > 4 --> this...
5
by: Csaba Gabor | last post by:
In Firefox 1.5 (this question is Mozilla specific as I am using greasemonkey) I would like to be able to use document.evaluate to return the first TD entry that shows ^\s*MySearchText\s*$. As I...
2
by: Björn Langhof | last post by:
Hello. I want to evaluate a XPath-Expression only on a subtree of the whole xml-document. 1. I select a node of the XML-document 2. Then a want to select specific nodes below the node chosen...
1
by: shellon | last post by:
Hi all: when I use XPather(a firefox extension) to evaluate the expression: "/html/body/table/tbody/tr/td/table/tbody/tr/td/div/ul/li" it tells me there are 7 matching Nodes. but when I use...
15
by: Phlip | last post by:
Javascripters: I have an outer page and an inner iframe. The outer page calculates some javascript, and wants the inner frame to run it. The inner frame should hit a page on the same (private)...
6
by: qianz99 | last post by:
unsigned char buffer; I'd like to put the following hex value into this array 01 1D 28 05 08 00 13 F0 33 19 19 00 35 05 08 00 64 F0 64 46 46 00 09 Is it any easy way to do it? Thanks a...
2
kadghar
by: kadghar | last post by:
Many people asks if there is a way to write a mathematical expression, writen as a string in a text box, so they can do something like: sub something_click() textbox2.text=eval(textbox1.text)...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.