Programming Articles - Page 2717 of 3366

Heap overflow and Stack overflow

Aman Kumar
Updated on 18-Jun-2025 18:31:25

691 Views

Heap and stack overflows are both types of buffer overflows that occur when a program attempts to write data beyond the allocated boundary of a buffer. Heap Overflow Heap is used to store dynamic variables. It is a region of process’s memory. malloc(), calloc(), resize() all these inbuilt functions are generally used to store dynamic variables. Following are the regions where heap overflow occurs − If we allocate dynamic large number of variables int main() { float *ptr = (int *)malloc(sizeof(float)*1000000.0)); } If we continuously allocate memory and do not free after using it. int main() { for (int i=0; i

What uses are there for “placement new” in C++?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

217 Views

In this section we will see what is the placement new operator in C++. This placement new is another variation of new operator. The normal new operator performs two things. It allocates memory, and then constructs an object in allocated memory.The new operator allocates memory in the heap section and constructs objects there. But for the placement new operator, it constructs object at the given address. To deallocate memory, we can use delete keyword if the memory is allocated using new operator. But for placement new there is no placement delete feature.So in a nutshell, placement new allows you to ... Read More

Placement new operator in C++

Aman Kumar
Updated on 18-Jun-2025 18:33:22

2K+ Views

In C++, we allocate the memory dynamically using the new operator. But there is a special version of this operator known as placement new operator. The new operator performs two things. It allocates memory, and then constructs an object in allocated memory. But for the placement new operator, it constructs object at the given address. What is Placement New? The placement new operator allows you to construct an object at a specific memory location. Its syntax lets you place an object at a pre-allocated memory address instead of letting the compiler allocate memory. new (address) Type (constructor_args); Where ... Read More

Conversion Operators in C++

Aman Kumar
Updated on 18-Jun-2025 18:35:59

2K+ Views

What is Conversion Operator Conversion operators are a type of operator overloading in C++. These operators are commonly known as type-cast operators. They enable a class or structure to specify how an object should be converted into another data type. Sometimes we need to convert concrete-type objects to some other type of objects or primitive data types. To make this conversion we can use a conversion operator. Following is the syntax to use the conversion: class ClassName { public: operator TargetType() const { // conversion logic } }; ... Read More

How do I add two numbers without using ++ or + or any other arithmetic operator in C/C++?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

339 Views

In this article we will see how to add two numbers without using arithmetic operators like +, ++, -, or --.To solve this problem, we can solve them using binary adder logic. In that case we were designed half adder and full adder. These adders can add one bit binary numbers. By cascading multiple adders, we have can create circuit to add bigger numbers.In that adder, we have performed XOR operation among the numbers, then for the carry we were performing the ANDing logic. These features are implemented here to add two numbers.Example Code Live Demo#include using namespace std; int ... Read More

C++ Program to Implement Hash Tables with Linear Probing

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

10K+ Views

A hash table is a data structure which is used to store key-value pairs. Hash function is used by hash table to compute an index into an array in which an element will be inserted or searched.Linear probing is a collision resolving technique in Open Addressed Hash tables. In this method, each cell of a hash table stores a single key–value pair. If a collision is occurred by mapping a new key to a cell of the hash table that is already occupied by another key. This method searches the table for the following closest free location and inserts the ... Read More

C++ Program to Implement Rolling Hash

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

1K+ Views

Rolling hash is a hash function in which the input is hashed in a window that moves through the input.Rabin-Karp is popular application of rolling hash. The rolling hash function proposed by Rabin and Karp calculates an integer value. For a string the integer value is numeric value of a string.The Rabin–Karp string search algorithm is often explained using a very simple rolling hash function that only uses multiplications and additions −H=c1ak-1+c2ak-2+….+ cka0.Where, a is a constant, and c1, c2….ck are the input characters. In order to manipulate Huge value of H, mod n is done.AlgorithmBegin    Declare a constant ... Read More

C++ Program to Implement Hash Tables with Double Hashing

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

3K+ Views

A hash table is a data structure which is used to store key-value pairs. Hash function is used by hash table to compute an index into an array in which an element will be inserted or searched.Double hashing is a collision resolving technique in Open Addressed Hash tables. Double hashing uses the idea of using a second hash function to key when a collision occurs.This is a C++ program to Implement Hash Tables chaining with double hashing.AlgorithmFor search a key:Begin    Declare Function SearchKey(int k, HashTable *ht)       int hashVal= HashFunc1(k, ht->s)       int stepSize= HashFunc2(k, ... Read More

C++ Program to Implement Hash Tables chaining with Singly Linked Lists

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

4K+ Views

A hash table is a data structure which is used to store key-value pairs. Hash function is used by hash table to compute an index into an array in which an element will be inserted or searched.This is a C++ program to Implement Hash Tables chaining with singly linked lists.AlgorithmFor insert:Begin    Declare Function Insert(int k, int v)       int hash_v = HashFunc(k)       HashTableEntry* p = NULL       HashTableEntry* en = ht[hash_v]       while (en!= NULL)          p = en          en= en->n     ... Read More

C++ Program to Implement Hash Tables Chaining with List Heads

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

654 Views

A hash table is a data structure which is used to store key-value pairs. Hash function is used by hash table to compute an index into an array in which an element will be inserted or searched.This is a C++ Program to Implement Hash Tables Chaining with List Heads.AlgorithmFor insert:Begin    Declare function Insert(int k, int v)       int hash_v = HashFunc(k)       if (ht[hash_v] == NULL)          ht[hash_v] = new ListHead(k, v)       else          ListHead *en = ht[hash_v]          while (en->n != NULL) ... Read More

Advertisements