473,386 Members | 1,609 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,386 software developers and data experts.

Increment and Decrement operators

b=a++ + ++a - a--;
Find the value of a?
Please tell me how can I find this.
Feb 22 '12 #1
2 1617
weaknessforcats
9,208 Expert Mod 8TB
There's no way to tell.

Compilers are free to evaluate variables in any oreder so you cannot change a variable more than once in the same statement.
Feb 22 '12 #2
Banfa
9,065 Expert Mod 8TB
This line of code invokes undefined behaviour because it accesses a variable (a) more than once between sequence points where one of those accesses is writing to the variables value.

Undefined behaviour is bad because under the action of undefined behaviour the program can literally do anything, it is not constrained in any way. You should avoid undefined behaviour at all costs.

Undefined Behaviour
You want to avoid undefined behaviour so find out what it is.

Sequence points
Sequence points are a basic part of the language notation, coupled with undefined behaviour by indicating when all side-effects of an operation have to be resolved. Read this and learn where they are.
Feb 23 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Hendrix | last post by:
Hi, I would like to pick four elements from a multidemensional array and use the content of those elements. I want to do this without all the subscript calls required for individual access, just...
4
by: John | last post by:
I was wondering why the STL RB Tree implementation is used when the iterators of map are incremented/decremented to yield successors and predecessors? This takes O(log n) time (and a lot of memory...
8
by: lovecreatesbeauty | last post by:
Hello experts, Why can this difference between prefix increment/decrement and postfix increment/decrement reside in built-in operators for built-in data types? Thanks. // test.cpp // //...
5
by: Ian Pilcher | last post by:
I'm trying to figure out if an increment to a variable of an integer type, followed by a decrement, (or vice versa) is guaranteed to restore the variable to its initial value, even if the first...
8
by: Angel Tsankov | last post by:
Should pre/post increment/decrement return const or non-const? What about other functions?
5
by: Stuart | last post by:
Hi all, Iv'e got a page that has a mass amount of input fields, all of which require a decimal figure. To make it easier when it comes to inputting data, I'm trying to setup + and - links that...
6
by: Kevin Walzer | last post by:
This code: #include <stdio.h> int main(void) { int n1, n2; //two integers n1 = 1; n2 = 1;
8
by: cpptutor2000 | last post by:
Could some C guru please help ? I have: int x = 20, y = 35; x = x++ + y++; y = ++x + ++y; printf("%d %d\n", x, y); The answers are 57, 94 I tried reasoning using the standard C semantics...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.