Found 7346 Articles for C++

C++ Program to Display Fibonacci Series

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

14K+ 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

C++ "Hello, World!" Program

karthikeya Boyini
Updated on 23-Jun-2020 16:25:01

14K+ Views

C++ is a general purpose programming language that supports procedural, object-oriented and generic programming. C++ is a superset of C and all valid C programs are valid in C++ as well.C++ supports object oriented programming with features such as data hiding, encapsulation, inheritance, polymorphism etc.Let us see the first C++ program that prints Hello, World!.Example#include using namespace std; int main() {    cout

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

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

904 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

Samual Sam
Updated on 18-Jun-2020 12:33:13

2K+ Views

PointersIn C, C++ programming languages, a pointer is a variable that holds the address of another variable.example#include using namespace std;   int main() {    //int variable    int i = 8;    //pointer variable    int * pI;    //assign the address of i to its pointer    pI = &i;    //print the number    cout

How can we read Python dictionary using C++?

Samual Sam
Updated on 30-Jul-2019 22:30:22

349 Views

There are many C++/Python bindings. It boils down to what you use to communicate between C++ and python to read python dictionaries in c++. Most of these libraries(like Boost) handle the parsing themselves. You could use an intermediate data transfer format like JSON or XML to pass data between the 2 languages and then serialize and deserialize data using the respective libraries in these languages for these formats.

Why we can't use arrow operator in gets and puts?

Pythonista
Updated on 22-Jun-2020 09:11:02

103 Views

You can't read user input in an un-initialized pointer. Instead, have a variable of the struct data type and assign its address to pointer before accessing its inner elements by → operatorexample#include struct example{    char name[20]; }; main(){    struct example *ptr;    struct example e;    puts("enter name");    gets(e.name);    ptr=&e;    puts(ptr->name); }OutputTypical result of above codeenter name Disha You entered Disha

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

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

290 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

189 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

50 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

Advertisements