strange sum
-
A harmonic mean of numbers 21 and 24 is 22.4, so the VC compiler takes a floor(harm_mean) as the most expected value.
Greetings - Gajatko Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
-
Fer Simoes wrote:
The question was: write the final result for this sum: int a = 5; int c = ++a + ++a + ++a;
Answer 1: I don't write crap code like that Answer 2: If your programmers do, I'm not working here Marc
sorry marc, it seems you did not understand the meaning of the post. Nobody here writes crap code :b, it is only for fun
Regards Fer Simoes
-
hi everybody, I have recently run into this when taking a silly C++ exam The question was: write the final result for this sum: int a = 5; int c = ++a + ++a + ++a; logically I Thought the result would be 21 and I tested it in two compilers: Visual C++ 6.0 says c == 22 Visual Studio 2005 says c == 24 I hop you enjoy this as much as I. Greetings
Regards Fer Simoes
This sort of thing also dependent on how compiler inplements it, like left to right or right to left. If from left to right or left to right c= ++a means c=6 now a=6 c=6+ ++a means c=7 now a=7 c=13+ ++a means c=8 now a=8 c=13+8 c=21 this results on GCC/g++ compiler. But some compiler evaluate first and then assignment like ++a=>>>a=6 ++a=>>a=7 ++a=>>>a=8 Now c=8+8+8=24 But i dont know how it's giving 22.. No points to give 22 as i think...
Truth Can'nt be changed
-
hi everybody, I have recently run into this when taking a silly C++ exam The question was: write the final result for this sum: int a = 5; int c = ++a + ++a + ++a; logically I Thought the result would be 21 and I tested it in two compilers: Visual C++ 6.0 says c == 22 Visual Studio 2005 says c == 24 I hop you enjoy this as much as I. Greetings
Regards Fer Simoes
This sort of problem we should not bothered. It can give any result depends on compiler inplements it how???
Truth Can'nt be changed
-
Fer Simoes wrote:
The question was: write the final result for this sum: int a = 5; int c = ++a + ++a + ++a;
Answer 1: I don't write crap code like that Answer 2: If your programmers do, I'm not working here Marc
I think it makes sense as a C++ exam question, to see if the student understands the operator precedence. I myself never rely on operator precedence, I always use parentheses.
-
This sort of thing also dependent on how compiler inplements it, like left to right or right to left. If from left to right or left to right c= ++a means c=6 now a=6 c=6+ ++a means c=7 now a=7 c=13+ ++a means c=8 now a=8 c=13+8 c=21 this results on GCC/g++ compiler. But some compiler evaluate first and then assignment like ++a=>>>a=6 ++a=>>a=7 ++a=>>>a=8 Now c=8+8+8=24 But i dont know how it's giving 22.. No points to give 22 as i think...
Truth Can'nt be changed
-
You can tell when a company goes to a lot of effort to make their compiler easy to use. The most expensive part of a project is the amount of debugging and fixing bugs. A compiler that can save this much time is a Good Thing.
Yes, good point. The example given is extreme and nobody in their right mind would code that way but I imagine more subtle examples that might slip through on a Friday afternoon are not hard to think up: int i = ++i1 + ++i1; // whoops, meant ++i2
Paul Sanders http://www.alpinesoft.co.uk