[Solved] C. for loop with chars

This char s[]=”TvNnFs”,*p; where s is an array of characters and p is character pointer, is looks like below s[0] s[1] s[2] s[3] s[4] s[5] s[6] —————————————— | T | v | N | n | F | s | \0 | —————————————— s 0x100 0x101 0x102 0x103 0x104 0x105 0x106.. (assume 0x100 is base … Read more

[Solved] C++ why std::string is much slower than C string

Quite interesting results. I’ve re-run the benchmark on 4.8.2 20140120 and got: strcmp : 1.938 secs std::string.compare(const char* s) : 1.842 secs std::string == std::string : 1.225 secs strncmp : 2.660 secs memcmp : 1.182 secs std::string.compareN : 1.711 secs strstr : 5.854 secs memmem : 1.187 secs std::string.find : 14.363 secs So std::string behaves … Read more

[Solved] Bizarre C++ code, trying to decipher

You didn’t specify the types, so I’m going to assume that these are all builtin C++ types, specifically arithmetic types (either integer type or a floating point type). If it is a user defined type, I can’t guarantee that anything I say below still applies. T& lhs.operator=(T& rhs) is the copy assignment operator (it could … Read more

[Solved] Why do I get a wrong answer in this C code?

You are invoking some very undefined behavior. The variable a in the function is at an address (probably on the stack) that is normally only accessible to the function. Decrementing that address results in an undefined location. You don’t know what’s there at all, so you have no idea what incrementing it by 8 will … Read more

[Solved] What is the difference between overloading the assignment operator and any other operator?

Here are two differences: An overloaded assignment operator must be a member of the class being assigned to; it cannot be declared as a free function. Copy and move assignment operators will be implicitly declared for your class if you do not declare them yourself (subject to certain restrictions). solved What is the difference between … Read more

[Solved] SQL code error in C#

The SQL statement is not the problem (you are able to execute it in SQL manager) and neither is it the call to AddWithValue because that won’t throw an ArgumentException based on the cause in mentioned in the exception message. So it must be something else. That leaves a constant and an expression using the … Read more

[Solved] how to read .dat files in c++ [closed]

Yes, you can use fstream for this. Here is some code you could use for splitting the data into an array devided by a delimiter. just change the DELIMITER to your delimiter. #include <iostream> using std::cout; using std::endl; #include <fstream> using std::ifstream; #include <cstring> const int MAX_CHARS_PER_LINE = 512; const int MAX_TOKENS_PER_LINE = 20; const … Read more

[Solved] Is there a way to run in parallel completeley unrelated tasks in C/C++

Introduction Yes, it is possible to run completely unrelated tasks in parallel in C/C++. This can be done using a variety of techniques, such as multi-threading, asynchronous programming, and message passing. Each of these techniques has its own advantages and disadvantages, and can be used to achieve different levels of parallelism. In this article, we … Read more

[Solved] Why dοes this code output 1?

The code can be roughly translated to the English: Start with a sum of zero then, for every number from 0 to 9 inclusive, add it to the sum if and only if the current sum is even. So, you’ll add zero to the sum (because the sum is currently even) after which the sum … Read more