Passing Arrays to Function in C++

The syntaxes and are exactly the same as when in a function parameter list (I left out the optional names). Additionally, an array name decays to a pointer to the first element when passed to a function (and not passed by reference) so both int firstarray[3] and int secondarray[5] decay to int*s. It also happens … Read more

Initializing an array of objects

I’m currently working on a card game, and I’m having trouble with some initialization code: The trouble is that my compiler’s telling me that cards++ is not an l-value. I’ve read up on the whole pointer-array equivalence thing, and I thought I understood it, but alas, I can’t get it to work. My understanding is … Read more

Floating point exception( core dump

You are getting Floating point exception because Number % i, when i is 0: Just start the loop at i = 2. Since i = 1 in Number % i it always be equal to zero, since Number is a int.

What is `CString`?

CString is neither a C nor a C++ type. It appears to be a Microsoft invention that is essentially an alternative to std::string: CString objects can grow as a result of concatenation operations. CString objects follow “value semantics.” Think of a CString object as an actual string, not as a pointer to a string. You can freely substitute CString objects for const char* and LPCTSTR function arguments. A conversion … Read more

When to use extern “C” in simple words? [duplicate]

You need to use extern “C” in C++ when declaring a function that was implemented/compiled in C. The use of extern “C” tells the compiler/linker to use the C naming and calling conventions, instead of the C++ name mangling and C++ calling conventions that would be used otherwise. For functions provided by other libraries, you will almost never need … Read more

What is meant by Resource Acquisition is Initialization (RAII)?

It’s a really terrible name for an incredibly powerful concept, and perhaps one of the number 1 things that C++ developers miss when they switch to other languages. There has been a bit of a movement to try to rename this concept as Scope-Bound Resource Management, though it doesn’t seem to have caught on just yet. … Read more

Conversion from string to char – c++

You can get a specific character from a string simply by indexing it. For example, the fifth character of str is str[4] (off by one since the first character is str[0]). Keep in mind you’ll run into problems if the string is shorter than your index thinks it is. c_str(), as you have in your comments, gives you a char* representation (the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)