473,399 Members | 3,401 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,399 software developers and data experts.

find value

hi everyone out there
can anyone give me the value of a(wn executed saperatly)
initially a=5
a+=(a++)+(++a)
a-=(--a)-(a--)
support ur answers with reasons (precedence,assoivity)
thanks in advance.

Nov 15 '05 #1
7 1822

pw********@yahoo.co.in wrote:
hi everyone out there
can anyone give me the value of a(wn executed saperatly)
initially a=5
a+=(a++)+(++a)
a-=(--a)-(a--)
support ur answers with reasons (precedence,assoivity)
thanks in advance.


You are trying to modify the variable "a" more than once without an
intervening sequence point. The behaviour is undefined and may produce
different values of variable
"a" on different implementations.
For more details, search for "sequence points" in this
newsgroup. You will find enough information.

Its always better not to use such expressions if there
are other better/simpler ways of doing the same.

Nov 15 '05 #2

give me the values saperately(2 values of a)

Nov 15 '05 #3

pw********@yahoo.co.in wrote:
give me the values saperately(2 values of a)

42 & 42. But there may be slight variations depending on the
temperature.

0. Learn some basic rules when you are going to post to a
newsgroup. There is enough information in this newsgroup only,
so search.
1. Check the FAQ. 3.2 should be of particular interest to you.
That said, read the whole of section 3, and if you still have some
time, the whole FAQ.

Nov 15 '05 #4

pw********@yahoo.co.in wrote:
give me the values saperately(2 values of a)

It could be anything 17,18 or 19.

a+= a++ + ++a;

Its not guaranteed that which of subexpression a++ or
++a would be evaluated first. Suppose, that some implementation
does a++ first and then ++a. Taking initial value of a=5,

a++ would take a initial value 5 before incrementing. Now,
since there is no sequence point after a++, its not guaranteed
if the location where "a" is stored has the updated value or not.
So,while evaluating ++a, "a" could be either 5 or it could be 6. Also,
when ++a is evaluated, again there's
is no guarantee if location "a" has been updated with the
incremented value. So, when you add (a++ + ++a) to a, you
are not sure what would be the value of a. It could be 5,6 or
even 7.
The only sequence point in this statement is "semicolon" after
which all the side effects due to this statement would have
been settled.

Nov 15 '05 #5
ju**********@yahoo.co.in writes:
pw********@yahoo.co.in wrote:
hi everyone out there
can anyone give me the value of a(wn executed saperatly)
initially a=5
a+=(a++)+(++a)
a-=(--a)-(a--)
support ur answers with reasons (precedence,assoivity)
thanks in advance.


You are trying to modify the variable "a" more than once without an
intervening sequence point. The behaviour is undefined and may produce
different values of variable
"a" on different implementations.
For more details, search for "sequence points" in this
newsgroup. You will find enough information.

Its always better not to use such expressions if there
are other better/simpler ways of doing the same.


It's always better not to use such expressions.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #6
ju**********@yahoo.co.in writes:
pw********@yahoo.co.in wrote:
give me the values saperately(2 values of a)

It could be anything 17,18 or 19.

a+= a++ + ++a;

Its not guaranteed that which of subexpression a++ or
++a would be evaluated first. Suppose, that some implementation
does a++ first and then ++a. Taking initial value of a=5,

a++ would take a initial value 5 before incrementing. Now,
since there is no sequence point after a++, its not guaranteed
if the location where "a" is stored has the updated value or not.
So,while evaluating ++a, "a" could be either 5 or it could be 6. Also,
when ++a is evaluated, again there's
is no guarantee if location "a" has been updated with the
incremented value. So, when you add (a++ + ++a) to a, you
are not sure what would be the value of a. It could be 5,6 or
even 7.
The only sequence point in this statement is "semicolon" after
which all the side effects due to this statement would have
been settled.


Sorry, but that's nonsense. Modifying an object twice between
sequence points invokes undefined behavior. That doesn't mean that
the expression can evaluated in any of several orders; it means the
behavior is undefined. The result can be 5, 6, 7, 42, sqrt(-1), a
week from next Wednesday, dental floss, or the third plxnrfq on the
left.

Most of these are unlikely in real life, of course, but you really can
get results that are inconsistent with any order of evaluation.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #7
pw********@yahoo.co.in wrote:
give me the values saperately(2 values of a)
Try actually reading the archives for the group. junky_fellow was
correct that you will find all the information you need if you search
for "sequence points" on this group.

Also, even when using Google provide context otherwise people often will
have no idea what you are responding to. Again, if you read the group
you will find lost of posts telling you have to do this.

Before you post in ANY group, read the FAQ and a weeks worth of postings
to find out what the group is about. You question is also answered in
the FAQ as much as it can be sensibly answered.

Your post which junky_fellow answered was:
hi everyone out there
can anyone give me the value of a(wn executed saperatly)
initially a=5
a+=(a++)+(++a)
a-=(--a)-(a--)
support ur answers with reasons (precedence,assoivity)
thanks in advance.


The answer is:
When the first statement is executed a daemon flies out of your nose.
The preceded is an ancient post in this group which you can find by
searching for nasal daemons in the group and selecting the earliest posts.
When the second statement is executed the daemon will put a stake
through your heart. No precedent is needed because nasal daemons can do
anything they feel like doing (and anything they don't feel like doing)
at any time.

In other words, anything can happen because, as you were told, the
behaviour is undefined.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #8

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

Similar topics

108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would...
13
by: mike | last post by:
I have ListArray with number in Eg: 1, 1.456, 2.43, 4, 6.78 next i have a decimal variable containing one number EG: 1.786 Could someone please tell me how i find the "closest match" number...
4
by: Arjen | last post by:
Hi, I need to add this inside an array: 1 3 2 4 3 2 4 5 5 1 I think of using this:
2
by: Chris Fink | last post by:
This should be relatively simple but I am unable to find an asp:button tag in a datalist footer. I have tried it numerous ways including the FindControl method from the many events that the...
67
by: PC Datasheet | last post by:
Transaction data is given with date ranges: Beginning End 4/1/06 4/4/06 4/7/06 4/11/06 4/14/06 4/17/06 4/18/06 4/21/06 426/06 ...
5
by: Draw | last post by:
Hi All, Just a thought, about the find() algorithm in the C++ STL. I read that the find algorithm can take a range of iterators. If it does not find the element it is looking for in that range...
8
by: brekehan | last post by:
If I have a class MyClass { ...bunch o data and methods int x; }; and a stl container of MyClass objects Is there a way to use std::find to get all the elements whose member x
5
gekko3558
by: gekko3558 | last post by:
I am writing a simple binary search tree (nodes are int nodes) with a BSTNode class and a BST class. I have followed the instructions from my C++ book, and now I am trying to get a remove method...
1
by: qiong | last post by:
Dear friends, Good evening, I have some problems with finding keyword ":\" for each cell. My objective is to find that keyword in each cell in each worksheet which represent the link. Eg:...
5
by: YaoBao | last post by:
Is any ColdFusion script I can put on my webpage that will create a search bar so people can type keywords to match it on the current page in my website? It will be exactly like the finder search bar...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.