Found 7197 Articles for C++

C++ Program to Implement Bitap Algorithm for String Matching

Aman Kumar
Updated on 20-May-2025 19:24:35

495 Views

The bitap algorithm is fuzzy string matching algorithm that is used to find approximate matches between a pattern and a text. The algorithm determines whether a given text contains a substring that is "approximately equal" to a given pattern, where approximate equality is defined in terms of Levenshtein distance (or number of edits) if the substring and pattern are within a given distance k of each other, then according to the algorithm they are equal. It begins by precomputing a set of bitmasks containing one bit for each element of the pattern. So we can do most of the work with ... Read More

Can a C++ virtual functions have default parameters?

Aman Kumar
Updated on 20-May-2025 19:29:14

827 Views

Yes, C++ virtual functions can have default parameters. The default parameter is the value provided during function declaration, such that the value can be automatically assigned if no argument is passed to them. In case any value is passed the default value is overridden and becomes a parameterized argument. Virtual Function A virtual function is a member function declared in a base class and can be overridden in a derived class. When we use a pointer or reference to the base class to refer to an object of the derived class, you can call a virtual function for that object. ... Read More

SQL using C/C++ and SQLite

Nitya Raut
Updated on 30-Jul-2019 22:30:25

2K+ Views

In this section, you will learn how to use SQLite in C/C++ programs.InstallationBefore you start using SQLite in our C/C++ programs, you need to make sure that you have SQLite library set up on the machine. You can check SQLite Installation chapter to understand the installation process.C/C++ Interface APIsFollowing are important C/C++ SQLite interface routines, which can suffice your requirement to work with SQLite database from your C/C++ program. If you are looking for a more sophisticated application, then you can look into SQLite official documentation.Serial NoAPI & Description1sqlite3_open(const char *filename, sqlite3 **ppDb)This routine opens a connection to an SQLite ... Read More

Calling virtual functions inside constructors in C++

Smita Kapse
Updated on 30-Jul-2019 22:30:25

292 Views

Virtual functions calling from a constructor or destructor is dangerous and should be avoided whenever possible as the virtual function we call is called from the Base class and not from the derived class.The reason is that in C++ Super-classes are constructed before derived classes. So, in the following example, as B must be instantiated, before D is instantiated. When B's constructor is called, it's not D yet, so the virtual function table still has the entry for B's copy of s().Example Code Live Demo#include using namespace std; class B {    public: B() {       s();    } ... Read More

Database Connectivity using C/C++

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

4K+ Views

In this section, you will learn how to use SQLite in C/C++ programs.InstallationBefore you start using SQLite in our C/C++ programs, you need to make sure that you have SQLite library set up on the machine. You can check the SQLite Installation chapter to understand the installation process.C/C++ Interface APIsFollowing are important C/C++ SQLite interface routines, which can suffice your requirement to work with SQLite database from your C/C++ program. If you are looking for a more sophisticated application, then you can look into SQLite official documentation.Serial NoAPI & Description1sqlite3_open(const char *filename, sqlite3 **ppDb)This routine opens a connection to an ... Read More

Difference between a virtual function and a pure virtual function in C++

Aman Kumar
Updated on 18-Jun-2025 18:40:06

7K+ Views

In C++, virtual and pure virtual functions are key features supporting polymorphism both allow different classes to respond uniquely to the same function call. What is Virtual Function A virtual function in C++ is a member function in a base class, which allows a function to be overridden in the derived class. This process helps in enabling runtime polymorphism. A virtual function is declared in the base class using the virtual keyword. Syntax Following is the syntax of the virtual function: class BaseClassName { public: virtual void func_name() { // implementation ... Read More

Pure virtual destructor in C++

Aman Kumar
Updated on 27-May-2025 16:34:52

782 Views

A pure virtual function is a function that has no implementation in the base class and must be overridden by any derived class. It is declared using = 0 in the base class. Pure Virtual Destructor When we want the base class to be abstract then we declare a pure virtual Destructor. A pure virtual Destructor can be declared in C++ after a destructor has been created as a pure virtual object. One of the most important things is that if a class contains a pure virtual destructor, it must provide a function body for the pure virtual destructor. ... Read More

Assertions in C/C++

Aman Kumar
Updated on 18-Jun-2025 18:46:54

476 Views

What is an Assertions in C/C++? An assertion is a statement used to test assumptions made by the program. When an assertion fails, the program displays an error and stops. This is mainly used for debugging. In C and C++, assertions are handled using the assert() macro defined in the (C) or (C++) header file. Following is the declaration for assert() Macro. #include // in C // or #include in C++ assert(expression); The parameter of this assert() is expression: This can be a variable or any C/C++ expression. If ... Read More

Execute both if and else statements simultaneously in C/C++

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

223 Views

In this section we will see how to execute the if and else section simultaneously in a C or C++ code. This solution is little bit tricky.When the if and else are executed one after another then it is like executing statements where if-else are not present. But here we will see if they are present how to execute them one after another.Example Code#include using namespace std; int main() {    int x = 10;    if(x > 5)   {       lebel_1: cout

C++ Program to Implement AVL Tree

Aman Kumar
Updated on 30-May-2025 18:42:56

23K+ Views

In this article, we will demonstrate how to implement an AVL tree. An AVL tree is a self-balancing binary search tree in which the height difference between the left and right subtrees (balance factor) of any node cannot exceed one. AVL TREE Following are the points of an AVL tree − Tree rotation is a way to change the structure of an AVL tree without changing the order of the elements. It helps keep the tree balanced by moving one node up and one node down. Tree rotations are mainly used ... Read More

Advertisements