Found 7346 Articles for C++

Is C++0x Compatible with C?

Srinivas Gorla
Updated on 30-Jul-2019 22:30:22

94 Views

Neither C++ (98) nor the new standard(C++0x or C++11) is fully compatible with C. C++ never was fully compatible with C.

What are the differences between -std = c++11 and -std = gnu++11?

George John
Updated on 24-Jun-2020 05:45:45

1K+ Views

GNU C++ compiler, g++, provides extensions to the C++ language. The difference between the two options is whether these GNU extensions that might violate the C++ standard are enabled or not. Note that some extensions can still be in effect when using -std = c++11, if they don't violate the standard.The list of extensions to the C++ language in GNU compiler can be found here − https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Extensions.html

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

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

317 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

255 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

535 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

395 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

380 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.

Advertisements