hi i am getting different answers for the same code in VC++ and
TURBOC++
The source code is as follows
What is the clarification i can get.Code:void main() { int a=1; printf("%d",++a + ++a); }
thanking you very much.
hi i am getting different answers for the same code in VC++ and
TURBOC++
The source code is as follows
What is the clarification i can get.Code:void main() { int a=1; printf("%d",++a + ++a); }
thanking you very much.
http://c-faq.com/expr/index.html
Your code is broken in more ways than there are lines of code, so what you get is entirely random and nothing to do with C.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
The output is 4.Code:int main() { int a=1; printf("%d", 2 * (a + 1)); return 0; }
Note: This program is C, not C++ (but you can compile it in a c++ compiler)
EDIT: Salem speaks the truth.
Last edited by myle; 07-15-2007 at 10:22 AM.
. . . assuming you include stdio.h, of course.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.