int c=2,a=5;
c = a++ - a;

I know the answer of this program. The result is 0.

But i want to know the working of this program(I'm a newbie to c++. So, please help me..)


If you do my high school graded writing assignment, then I will do your C++ program! Deal or no deal? ;)

Just joking, however as your first post you've made many mistakes.
You don't create a title saying "gimmeh the solution", you shortly describe your problem.

It is not considerably a problem that you for some reason have to create this program, a problem would be that the program you are making will not function.

So, you're using code tags. I almost starting complaining about that too, as most newcomers don't do that. Good job on that one.

You need to describe your problem.
Does the code compile and link properly?

No one will give you a working program, but just as a sidenote - how would we know what working program to create for you, if you haven't told what it should be capable of doing!? ;)

From what I can see, you should want to put std:: in from of cout so it reads std::cout << c; , and #include <iostream> instead of #include <iostream.h> .

Good luck anyway.

As Excizted said u should describe ur problem. Here u wrote

But i want to know the working of this program

what does it mean??? R u asking the purpose of this program or asking that how does the program working?? if u want to know how does the program working then here it is

#include<iostream.h> /*<iostream.h> is an old style so its better to use just 
main()    //here must be return type
int c=2,a=5;
c = a++ - a; /* here first of all the value of a is increased 1. and the u r 
                substacting from a to so when it is increasing the 1 then the value 
                of a become 6. so 6-6 is 0.*/   
cout<<c; //std::cout shuld be used

The answer is that the program does not work, because the line that assigns a value to c has undefined behavior. The behavior is undefined because it attempts both to fetch and store the value of a single object between sequence points.

Because the program does not work, there is no need to spend time understanding why it works.

This article has been dead for over six months. Start a new discussion instead.