Senior Software Developer - 13 years in software development - Posts in German/English/Turkish - BOUN - CMPE - MSc. in Software Engineering - a chess enthusiast
https://t.co/5MrnZrUsFo
TYT/AYT hazırlık için geometri soruları soran bir uygulama geliştirdim. Şu anda 1622 soru var içinde. Mobil/Web/Tablet uyumlu. Deneyen olursa yorum yaparsa sevinirim.
@Careerbuddha111 if there is no customer_id in customers table but there are customers this query will not throw error and will delete the whole orders table.
What is written in the console and why?
Note: Action is
>>
delegate void System.Action()
>>
Encapsulates a method that has no paramaters and does not return a value.
It prints 333 because the lambda doesn’t copy the value of i at the moment it’s created. It captures the variable itself. A for loop has only one i shared across all iterations. By the time the actions run, the loop has finished and i is 3, so all three print 3.
Never prints anything. It’s an infinite loop.
A float has a 24-bit mantissa, so it can represent every integer exactly only up to 2²⁴. When f is 16,777,216, f + 1 gives 16,777,217, which isn’t representable. It rounds back to 16,777,216
2,147,483,649 times, not infinite.
i starts at 0 and counts down: 0, −1, −2, … until int.MinValue (−2,147,483,648). 2,147,483,649 iterations. The next i-- overflows, and since C# is unchecked by default, i wraps around to int.MaxValue. That's not < 10, so the loop exits.
@fluffy8unny In C#, int is always 32 bits. It’s an alias for System.Int32, fixed by the language spec on every platform: 32-bit, 64-bit, x86, ARM, all of them.
@gilles504 In a checked context (checked { } or the CheckForOverflowUnderflow compiler option), an OverflowException is thrown. But in an unchecked context (the default), it is not infinite.
@ChromMob It isn’t hardware-dependent either. The CLR (ECMA-335) specifies int32 as two’s complement, and the IL sub instruction wraps without checking. The runtime guarantees the same result on x86, ARM, or anything else. No .NET platform saturates.
@ChromMob In c/c++ you are right, but this is c# code.
In an unchecked context (the default), the high-order bits are discarded, so the value wraps using two’s complement. int.MinValue - 1 is guaranteed to be int.MaxValue.