Found 27104 Articles for Server Side Programming

What is the difference between C++0x and C++11?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:22

316 Views

C++ and C Standards are usually named after the year they are published in. For example, in C++, the original Standard was published in 1998, so it is called C++98, and its first correction, published in 2003 is called C++03.For the next revision, it was supposed that the next Standard after would be done by 2008, but since it was uncertain, it was named C++0x, where the x stood for either 8 or 9. Though planning shifted and it is now called C++11. So, C++0x was the name for the standard before it was published. Once it was finalized in ... Read More

What is the use of "placement new" in C++?

Abhinanda Shri
Updated on 24-Jun-2020 05:46:44

247 Views

In a nutshell, placement new allows you to "construct" an object on memory that's already allocated to a given variable. This is useful for optimizations as it is faster to not reallocate and reuse the same memory that is already assigned to it. It can be used as follows −new (address) (type) initializerWe can specify an address where we want a new object of the given type to be constructed. Example#include using namespace std; int main() {    int a = 5;    cout

C++ vs C++0x vs C++11 vs C++98

Smita Kapse
Updated on 11-Feb-2020 11:15:38

1K+ Views

C++98 was the first edition of the C++ standard. It had defined all the basic language constructs, the STL, and the standard library.C++03 was the next revision to this standard. This was majorly a considered a bugfix for the standard as it corrected 92 core language defect reports, 125 library defect reports, and included only one new language feature: value initialization.C++0x was the name of the work in progress that was expected to complete by 2008-09 but finally completed in 2011.C++11 was the modern C++ standard published in 2011. This brought many major extensions and improvements to the existing language. ... Read More

What is Rule of Five in C++11?

Chandu yadav
Updated on 24-Jun-2020 05:50:29

534 Views

The rule of five is applied in C++ for resource management. Resource management frees the client from having to worry about the lifetime of the managed object, potentially eliminating memory leaks and other problems in the C++ code. But this management comes at a cost. The Rule of The Big Five states that if you have to write one of the following functions then you have to have a policy for all of them. If we have an Object Foo then we can have a FooManager that handles the resource Foo. When implementing FooManager, you'll likely all need the following ... Read More

Rule of Three vs Rule of Five in C++?

George John
Updated on 24-Jun-2020 05:51:52

394 Views

The Rule of three is a rule of thumb when using C++. This is kind of a good practice rule that says that If your class needs any ofa copy constructor, an assignment operator, or a destructor, defined explicitly, then it is likely to need all three of them.Why is this? Its because, if your class requires any of the above, it is managing dynamically allocated resources and would likely be needing the other to successfully achieve that. For example, if you require an assignment operator, you would be creating copies of objects currently being copied by reference, hence allocating ... Read More

Why aren't variable-length arrays part of the C++ standard?

Abhinaya
Updated on 24-Jun-2020 05:52:35

378 Views

Having to create a potential large array on the stack, which usually has only little space available, isn't good. If you know the size beforehand, you can use a static array. And if you don't know the size beforehand, you will write unsafe code. Variable-length arrays can not be included natively in C++ because they'll require huge changes in the type system.An alternative to Variable-length arrays in C++ is provided in the C++ STL, the vector. You can use it like −Example#include #include using namespace std; int main() {    vector vec;    vec.push_back(1);    vec.push_back(2);    vec.push_back(3);   ... Read More

How do I declare a two-dimensional array in C++ using new?

Chandu yadav
Updated on 11-Feb-2020 11:07:10

1K+ Views

A dynamic 2D array is basically an array of pointers to arrays. So you first need to initialize the array of pointers to pointers and then initialize each 1d array in a loop.example#include using namespace std; int main() {    int rows = 3, cols = 4;    int** arr = new int*[rows];    for(int i = 0; i < rows; ++i)    arr[i] = new int[cols];    return 0; } This will create an 2D array of size 3x4. Be vary of clearing the memory in such cases as you'll need to delete the memory in the ... Read More

Difference between #include and #include "filename" in C/C++?

Anvi Jain
Updated on 30-Jul-2019 22:30:22

2K+ Views

The difference between the two forms is in the location where the preprocessor searches for the file to be included.#include The preprocessor searches in an implementation-dependent manner, it searches directories pre-designated by the compiler. This method is usually used to include standard library header files.#include "filename"The preprocessor searches in the same directory as the file containing the directive. If this fails, then it starts behaving like the #include form. This method is usually used to include your own header files.

When to use virtual destructors in C++?

Govinda Sai
Updated on 11-Feb-2020 11:05:48

678 Views

Scott Meyers in Effective C++ says −If a class has any virtual function, it should have a virtual destructor, and that classes not designed to be base classes or not designed to be used polymorphically should not declare virtual destructors.So you should declare destructors virtual in polymorphic base classes. This is because if you create an object of base class using a derived constructor −Base *b = new Derived(); // use b delete b;If Base's destructor is not virtual then delete b has undefined behavior in this case. The call to the destructor will be resolved like any non-virtual code. ... Read More

Difference between const int*, const int * const, and int const * in C/C++?

George John
Updated on 11-Feb-2020 11:04:26

3K+ Views

The above symbols mean the following −int* - Pointer to int. This one is pretty obvious. int const * - Pointer to const int. int * const - Const pointer to int int const * const - Const pointer to const intAlso note that −const int * And int const * are the same. const int * const And int const * const are the same.If you ever face confusion in reading such symbols, remember the Spiral rule: Start from the name of the variable and move clockwise to the next pointer or type. Repeat until expression ends.

Advertisements