[Solved] Why not have all variables be a constexpr? [closed]

[ad_1] First of all not all variables can be made constexpr. For example int x; std::cin >> x; Obviously x cannot be constexpr. The value it will have after it has been read from input is not a compile-time constant. Second, constexpr is part of the contract of a variable or function. By marking it … Read more

[Solved] Best way to multi-thread? [closed]

[ad_1] The correct (standard) way to do this on C and Windows is with __beginthreadex. This is usually preferred to calling CreateThread directly as CreateThread doesn’t init C runtime support for the thread. So if you create a thread using CreateThread, and call a CRT function, bad stuff can/will happen. Note that __beginthreadex calls CreateThread … Read more

[Solved] How many bytes will be deallocated with free() after changing the pointer?

[ad_1] As the man page for free will tell you, any argument except a pointer returned from malloc has undefined behaviour: The free() function frees the memory space pointed to by ptr, which must have been returned by a previous call to malloc(), calloc() or realloc(). Otherwise, or if free(ptr) has already been called before, undefined behavior occurs. If ptr is NULL, no operation … Read more

[Solved] Forming the smallest number [closed]

[ad_1] As others have pointed out sorting and removing duplicates is possible. But how about this algorithm (in pseudocode, implementation is left to the reader)? bool contains(int x, int digit); // returns true if x contains digit in base 10 notation int res = 0; for (int digit = 0; digit <= 9; ++i) { … Read more

[Solved] Convert string BigInteger with base 16 in c#

[ad_1] Use BigInteger.Parse with a style of NumberStyles.HexNumber: using System; using System.Globalization; using System.Numerics; class Program { static void Main() { var number = BigInteger.Parse(“728faf34b64cd55c8d1d500268026ffb”, NumberStyles.HexNumber); Console.WriteLine(number); } } Output: 152278043568215137367088803326132908027 [ad_2] solved Convert string BigInteger with base 16 in c#

[Solved] VS __forceinline in cpp [closed]

[ad_1] Yes you can, and it’s actually enforced really well (unlike gcc/clang etc, where __attribute__((always_inline)) is unfortunatly still optional for the compiler, depending on multiple other compiler flag settings). The keyword works in all versions of Visual Studio. [ad_2] solved VS __forceinline in cpp [closed]

[Solved] Complex C program [closed]

[ad_1] Assuming your pool of characters is sorted and without repetitions (may need some preprocessing), generating the desired strings in lexicographic order is automatic (in the approach I have in mind). Look at the short example of all nonempty strings that can be generated from “ABC” with the restrictions: A AB ABC AC ACB B … Read more