Found 7197 Articles for C++

C++ Program to Display Fibonacci Series

Samual Sam
Updated on 23-Jun-2020 16:24:22

16K+ Views

The fibonacci series contains numbers in which each term is the sum of the previous two terms. This creates the following integer sequence −0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377…….The recurrence relation that defines the fibonacci numbers is as follows −F(n) = F(n-1) + F(n-2) F(0)=0 F(1)=1Programs to Display Fibonacci SeriesThere are two methods to display fibonacci series i.e. using dynamic programming and recursive programming. These are further explained as follows −Dynamic ProgrammingExample#include using namespace std; void fib(int n) {    int f[n];    int i;    f[0] = 0;    f[1] ... Read More

How to get last 2 characters from string in C# using Regex?

Sreemaha
Updated on 22-Jun-2020 12:16:45

1K+ Views

Set the string −string str = "Cookie and Session";Use the following Regex to get the last 2 characters from string −Regex.Match(str,@"(.{2})\s*$")The following is the code −Example Live Demousing System; using System.Text.RegularExpressions; public class Demo {    public static void Main() {       string str = "Cookie and Session";       Console.WriteLine(Regex.Match(str,@"(.{2})\s*$"));    } }Outputon

C/C++ Pointers vs Java references

Nishu Kumari
Updated on 09-May-2025 11:34:00

2K+ Views

In this article, we will show you the difference between C/C++ pointers and Java references. C/C++ use pointers to manually control how memory is used and accessed. Java, on the other hand, does not support pointers and uses references instead, which manage memory automatically. Pointer in C/C++ A pointer is a variable that holds the address of another variable in memory. It gives you direct access to that memory, which is powerful but can lead to errors if not used carefully. Syntax Here's the syntax where we declare a pointer with an asterisk(*) ... Read More

How can we read Python dictionary using C++?

Samual Sam
Updated on 28-Aug-2025 09:29:08

542 Views

A dictionary in Python is a collection of key-value pairs where each key must be unique. The lists, which are indexed by numbers, are accessed using keys that can be immutable types, strings, numbers, or tuples. Lists cannot be used as keys because they can be modified. Dictionaries are created using {}, and key-value pairs are added with commas. We can store, retrieve, and delete values using their keys. Using the list() returns all keys, while sorting them. To check if a key exists, we can use the in keyword. If a key is replaced, then its old value is replaced. ... Read More

Java is also not pure object-oriented like c++

Pythonista
Updated on 30-Jul-2019 22:30:22

414 Views

the main() method in Java code is itself inside a class. The static keyword lets the main() method which is the entry point of execution without making an object but you need to write a class. In C++, main() is outside the class and writing class it self is not mandatory. Hence, C++ is not a pure object oriented language bu Java is a completely object oriented language.

What is "Argument-Dependent Lookup" ("Koenig Lookup") in C++?

Chandu yadav
Updated on 12-Feb-2020 06:34:31

341 Views

Argument-dependent lookup(ADL) is a protocol for looking up unqualified function names in function-call expressions.These function call expressions include implicit function calls to overloaded operators.The function names are looked up in the namespaces of their arguments in addition to the scopes and namespaces considered by the usual unqualified name lookup. Argument-dependent lookup makes it possible to use operators defined in a different namespace. Examplenamespace MyNamespace{    class A {};    void f( A &a, int i) {} } int main() {    MyNamespace::A a;    f( a, 0 );    //calls MyNamespace::f }The lookup of a function call to f was dependent ... Read More

What's the difference between "STL" and "C++ Standard Library"?

Govinda Sai
Updated on 24-Jun-2020 06:31:32

2K+ Views

The Standard Template Library (STL) is a software library for the C++ programming language that influenced many parts of the C++ Standard Library. It provides four components called algorithms, containers, functions, and iterators. Note that the term "STL" or "Standard Template Library" does not show up anywhere in the ISO 14882 C++ standard. So referring to the C++ standard library as STL is wrong, ie, STL and C++ Standard Library are 2 different things with the former being the subset of the latter.The STL consists ofContainersThe STL contains sequence containers and associative containers. Containers are objects that store data. The ... Read More

Why should C++ programmers minimize use of 'new'?

Ankith Reddy
Updated on 02-Mar-2020 08:07:45

132 Views

new is used for dynamic memory allocation. The memory allocated in this case goes on the heap. There are several costs associated with this type of memory allocation along with the programmer having to do manual memory cleaning and management. This type of allocation must be used when − You don't know how much memory you need at compile time.You want to allocate memory which will persist after leaving the current block.Other than these, there are very few cases where dynamic memory allocation is required. This is because, in C++, there is the concept of a destructor. This function gets called ... Read More

What is a "translation unit" in C++

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

2K+ Views

A translation unit is any preprocessed source file.A translation unit is the basic unit of compilation in C++. This unit is made up of the contents of a single source file after it passes through preprocessing. It contains included any header files without blocks that are ignored using conditional preprocessing statements like ifdef, ifndef, etc.A single translation unit can be compiled into an object file, library, or executable program.

Read whole ASCII file into C++ std::string

George John
Updated on 03-Dec-2024 09:40:15

15K+ Views

This is a simple way to read whole ASCII file into std::string in C++ − Algorithm Here is the algorithm we will follow to Read the whole ASCII file into C++ std::string. Begin  Declare a file a.txt using file object f of ifstream type to perform a read operation.  Declare a variable str of string type.  If(f) Declare another variable ss of ostringstream type. Call rdbuf() function to read the data of the file object. Put the ... Read More

Advertisements