Category: C++ Interview Questions
What is a Memory Leak in C++ ?
In this article we will discuss what is Memory Leak C++ and why its harmful for applications. Memory Leak Advertisements Memory leak in is a kind of Bug that kills your application slowly by first making it slow and then eventually crashing it. How Does Memory Leak happens: Frequently Asked: What is a Memory Leak …
Designing a Thread Pool Framework Part 1: What’s the need of a Thread Pool
In this we will discuss what is a Thread pool and why do we need Thread Pools. Many times you encounter a situation where where you need to perform several tasks in parallel to improve the performance of application. These Tasks can be anything like, Advertisements Encrypting a file. Calculating hash of a file. Performing …
Designing a Thread Pool Framework Part 1: What’s the need of a Thread PoolRead More
How does new and delete operator works internally ?
In this article we will discuss how new and delete operator works internally in C++.new operator is used to dynamically allocate memory on heap and delete operator is used to delete the memory from the heap allocated by new operator. Usage example of new and delete operator is as follows, #include <iostream> class Sample { …
How does new and delete operator works internally ?Read More
Handling Out Of Memory Errors in Code
In this article we will discuss how to Handle Out of Memory errors in a C++ Application. Each process has a limited free storage or heap associated with it for dynamic memory allocation. If application consumes all the memory from heap then process will crash with out of memory error. Advertisements Check out following example, …
Difference between delete & []delete and rise of Memory Leaks
In this article we will discuss the difference between delete &Â []delete and how mixing new [] with delete can give rise to Memory Leaks. To allocate memory dynamically on heap we use new[] operator i.e. Advertisements class Sample; Sample * ptrArr = new Sample[5]; Here new[] performs following operations internally, In first step, it …
Difference between delete & []delete and rise of Memory LeaksRead More
Restrict dynamic deletion of objects created on stack
Many times we encounter a situation where we need to delete a pointer but we are not sure that how this pointer is created i.e. either on Heap or on stack. Check out this function, Advertisements class Dummy; void deletePointer(Dummy * ptr) { // Do you know this passed pointer was // created on heap …
Restrict dynamic deletion of objects created on stackRead More
Overloading new and delete operators at Global and Class level
In this article we will discuss why we should overload new and delete operator and how to do it. When we create a new Object on heap by calling new operator then it does following things internally, Advertisements First it allocates the required memory by calling operator new i.e. operator new returns the pointer top …
Overloading new and delete operators at Global and Class levelRead More
what’s placement new operator and why do we need it.
In this article we will discuss what is placement new operator and what’s its need. Need of placement new operator Every when we create a new object using new operator, memory is allocated on heap i.e. Advertisements int * ptr = new int; But there might be scenarios when we want to dynamically create an …
what’s placement new operator and why do we need it.Read More
deleting this pointer and internal details of this pointer
In this article we will discuss what is exactly this pointer and what happens if we delete this pointer. what is this pointer? this pointer is a kind of pointer that can be accessed only inside non static member function and it points to the address of the object which has called the member function. …
deleting this pointer and internal details of this pointerRead More
How to pass variable arguments in a function
In this article we will discuss how to pass variable number of arguments in a function. Requirement: Advertisements Suppose I want to create a function that take variable number of arguments and use them to perform some task. For example, Create a function that will return the sum of all the passed arguments i.e. Frequently …