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

Regarding increment operator implementation and output explanation

#include<stdio.h>
int main()
{
int i=10;
printf("%d\t%d\t%d\t%d",i++,i++,i++,i++);
}
why output is
12 11 10
and not
10 11 12 ?
Oct 22 '16 #1
1 1063
weaknessforcats
9,208 Expert Mod 8TB
C++ evaluates variables before doing things with them. The order of evaluation might be left to right or it may be right to left or some other way. The C++ spec doesn't care.

If you have changed a variable more then once in a statement, your results are indeterminate.
Oct 22 '16 #2

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

Similar topics

2
by: Tony Burrows | last post by:
I know that in many C/C++ compilers using i++ is faster/ more efficient than i = i+1. Is it true for Java as well? Tony
1
by: MSDousti | last post by:
Hi, I'm confused with C++'s unary increment operator(++). Consider the following code: ////////////////////////////////////////////////////////////////////// #include <iostream> using...
10
by: riteshtijoriwala | last post by:
Anyone has any idea on why is there no post/pre increment operators in python ? Although the statement: ++j works but does nothing
6
by: nagarajanj | last post by:
#include<iostream.h> void main() { int i = 10; clrscr(); cout << i << i++ << ++i; getch(); }
7
by: laikon | last post by:
Hello, everyone, below is the program to calculate an expression of increment operator, the result j is 4 and i is 8 seems unbelieveable, so what is the rule of such expression? int i , j = 2;...
4
by: mebbert | last post by:
I was testing the increment operator in Perl and found a different behavior from other languanges. my $i = 1; print ++$i + ++$i . "\n"; The above code prints out the answer 6, instead of 5 as...
65
by: deepak | last post by:
Hi, For the following program the output I'm getting is not the one I expected. main() { int i = 3; i = i++;
2
by: mohammad ismail aakhil | last post by:
i have overladed unary ++ both pre and postfix increment operator using member function. both the operator function differ by arguements.v use a additional argunent of type int. how does complier...
15
by: somenath | last post by:
Hi All, I am not able to understand the behavior of the bellow mentioned program. #include<stdio.h> int main(void) { printf("\n Size = %d \n",sizeof 1<0); return 0;
5
by: simudream | last post by:
//hi maybe helpful others can look at this code and //tell me why the class code won't behave like //intrinsic types with post and pre increment //Version: 1.00 #include <iostream> using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.