Found 7346 Articles for C++

How to pass objects to functions in C++?

Ankitha Reddy
Updated on 30-Jul-2019 22:30:22

598 Views

There are four ways of passing objects to functions. Let's assume you have a class X and want to pass it to a function fun, then − Pass by value This creates a shallow local copy of the object in the function scope. Things you modify here won't be reflected in the object passed to it. For example, Declaration void fun(X x); Calling X x; fun(x); Pass by reference This passes a reference to the object to the function. Things you modify here will be reflected in the object passed to it. No copy of the ... Read More

Why accessing an array out of bounds does not give any error in C++?

Rishi Rathor
Updated on 30-Jul-2019 22:30:22

1K+ Views

This is due to the fact that C++ does not do bounds checking. Languages like Java and python have bounds checking so if you try to access an out of bounds element, they throw an error. C++ design principle was that it shouldn't be slower than the equivalent C code, and C doesn't do array bounds checking.So if you try to access this out of bounds memory, the behavior of your program is undefined as this is written in the C++ standard. In general, whenever you encounter undefined behavior, anything might happen. The application may crash, it may freeze, it ... Read More

What is the size of int, long type in C++ standard?

Chandu yadav
Updated on 24-Jun-2020 06:05:04

275 Views

The C++ standard does not specify the size of integral types in bytes. It specifies the minimum range these types must be able to hold.The size in bits can be easily found from the specified minimum range.Not referring to the standard but the commonly used sizes for various platforms are −For 32-bit systems, the standard is ILP32 — that is, int, long and pointer are all 32-bit quantities.For 64-bit systems, the Unix standard is LP64 — long and pointer are 64-bit (but int is 32-bit). The Windows 64-bit standard is LLP64 — long and pointer are 64-bit (but long and ... Read More

What are Aggregates and PODs in C++?

George John
Updated on 11-Feb-2020 12:49:57

510 Views

POD is an acronym in C++ that means plain old data. It is a class/struct that ONLY has member variables and no methods, constructors, destructors, virtual functions, etc. For example, Example#include using namespace std; // POD struct MyStruct {    int key;    string data; }; int main() {    struct MyStruct s;    s.key = 1;    s.data = "hello";    return 0; }The struct MyStruct has no user defined ctor, dtor, etc and hence is a POD.An aggregate is an array or a class with no user-declared constructors, no private or protected non-static data members, no base ... Read More

What is a lambda expression in C++11?

V Jyothi
Updated on 24-Jun-2020 06:06:07

280 Views

C++ STL includes useful generic functions like std::for_each. Unfortunately, they can also be quite cumbersome to use, particularly if the functor you would like to apply is unique to the particular function. So this function that you'll create will be in that namespace just being used at that one place. The solution to this is using anonymous functions.C++ has introduced lambda expressions in C++11 to allow creating anonymous function.example#include #include #include // for_each using namespace std; int main() {    vector myvector;    myvector.push_back(1);    myvector.push_back(2);    myvector.push_back(3);    for_each(myvector.begin(), myvector.end(), [](int x) {     ... Read More

Why do we use extern "C" in C++ code?

Priya Pallavi
Updated on 30-Jul-2019 22:30:22

1K+ Views

You need to use extern "C" in C++ when declaring a function that was implemented/compiled in C.Using extern "C" lets the compiler know that we want to use C naming and calling conventions. This causes the compiler to sort of entering C mode inside our C++ code. This is needed because C++ compilers mangle the names in their symbol table differently than C compilers and hence behave differently than C compilers.

What are POD types in C++?

Arjun Thakur
Updated on 02-Mar-2020 07:55:47

1K+ Views

POD is an acronym in C++ that means plain old data. It is a class/struct that ONLY has member variables and no methods, constructors, destructors, virtual functions, etc. For example,Example#include using namespace std; // POD struct MyStruct {     int key;     string data; }; int main() {     struct MyStruct s;     s.key = 1;     s.data = "hello";     return 0; }The struct MyStruct has no user-defined ctor, dtor, etc and hence is a POD.

C++11 Overview

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

800 Views

C++11 is the modern C++ standard published in 2011. This brought many major extensions and improvements to the existing language. It was approved by International Organization for Standardization (ISO) on 12 August 2011 and replaced C++03.C++11 was also known as C++0x. This is because, 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. ... Read More

The Biggest Changes in C++11

Nikitha N
Updated on 24-Jun-2020 05:56:48

134 Views

C++11 was the modern C++ standard published in 2011. This brought many major extensions and improvements to the existing language. Following are the major changes/additions of C++11 −Initializer listsAutomatic type deductionRvalue references and move constructorsconstexpr – Generalized constant expressionsModification to the definition of plain old dataUniform initializationRange-based for loopLambda functions and expressionsAlternative function syntaxExplicit overrides and finalA constant null pointer, nullptrStrongly typed enumerationsRight angle bracket not being treated as an operator at appropriate placesVariadic templatesMultithreading memory modelAdded Hash tables to the STLAdded Regular expressions to the Standard LibraryAdded General-purpose smart pointers like shared_ptr, weak_ptr, etcAnd many more. You can get ... Read More

C++ Standards Support in GCC

Vrundesha Joshi
Updated on 11-Feb-2020 12:54:12

922 Views

GCC supports different dialects of C++, corresponding to the multiple published ISO standards. Which standard it implements can be selected using the -std= command-line option.C++98 − GCC has full support for the 1998 C++ standard as modified in 2003 and renamed to C++03 and some later defect reports.C++11 − GCC 4.8.1 was the first complete implementation of the 2011 C++ standard, previously known as C++0x.C++14 − GCC has full support for the latest revision of the C++ standard, which was published in 2014.C++17 − GCC has experimental support for the next revision of the C++ standard, which is expected to ... Read More

Advertisements