Same code, different output in C# and C++ -
c#:
using system; using system.collections.generic; using system.linq; using system.text; namespace consoleapplication1 { class program { static void main(string[] args) { int = 11; int b = 2; -= b -= -= b += b -= a; system.console.writeline(a); } } } output:27
c++:
#include "stdafx.h" #include<iostream> int _tmain(int argc, _tchar* argv[]) { int = 11; int b = 2; -= b -= -= b += b -= a; std::cout<<a<<std::endl; return 0; } output:76
same code has differernt output, can tell why ? appreciated!!
in c# code defined , equivalent following:
a = - (b = b - (a = - (b = b + (b = b - a)))); the innermost assignments not relevant here because assigned value never used before variable reassigned. code has same effect:
a = - (b = b - (a - (b + (b - a)))); this same as:
a = - (b = (b * 3) - (a * 2)); or simpler:
b = (b * 3) - (a * 2); -= b; however, in c++ code gives undefined behaviour. there no guarantee @ do.
Comments
Post a Comment