“Design a parking lot” is a common interview question for senior software developers.

The problem statement is very similar to Grokking object oriented design interview question. https://www.educative.io/courses/grokking-the-object-oriented-design-interview/gxM3gRxmr8Z.

Requirements are

  1. The parking lot is a 10 floor building with multiple entry and exit points, both electric and non-electric cars can park. Each floor has 100 parking spots, out of which 4 are reserved for handicapped people. Only top 5 floors can be used for electric cars. The 10th floor is complete electric, other 4 floors, each have 50 spots reserved for electric cars. A non electric car can park in an electric car spot.
  2. The customer get the ticket at the entry point, the…

Performance depends on the underlying stream buffer.

std::endl writes a newline to the output stream and flushes it. In most cases, the developer doesn’t need to flush. Flushing operation is expensive, because it involves a system call. Instead of std::endl, you can simply write “\n”. Then the content will be flushed if the content size is more than the buffer size or the application closes.

But this is always not true.

For a program, three text streams are always provided.

  1. standard input
  2. standard output
  3. standard error

Both standard input and standard output are fully buffered. Standard error is line buffered.

Difference between fully buffered, unbuffered and line buffered stream

For fully buffered stream, characters are accumulated…

C++11 thread = native thread + language specifications

In an application, sometimes we need faster processing. One of the many ways to achieve faster processing is by doing many things simultaneously. This is called parallelism. This can be done by creating multiple processes or multiple threads. We can call it an execution unit. An execution unit is assigned to a hardware processor by the operating system scheduler. Even if a system has only a limited number of processors, we still can create more threads or processes to take advantage of the fact that many things in an application are IO-bound. Doing IO operations are slow and the CPU…

std::optional is a type wrapper which wraps that type and an optional flag which says about the nullability of that type.

Sometimes we create an object which contains no valid data. We often a associate a flag or a special value, which decides the validity of the data. For example,

  • a pointer with value nullptr is a pointer points to no location.
  • an id type with an allowed value of 0, which says the id is invalid if 0 or it’s a valid if more than 0.
unsigned int getId(const std::string &name)
if (name == "test") {
return 1;

if (name == "foo") {
return 2;

return 0;
int main() { std::vector<std::string> names {"test", "foo", "bar" }…

Structured binding allows you to initialize multiple variables with individual elements of a structure, tuple, or array.

Photo by luis gomes from Pexels

Often, a function will return multiple values packed in a structure. In good old C++ you need to assign it to a struct variable and access the individual members from there. In pre-C++17, however, you need to assign the return value to a struct variable and access the individual elements (as shown below). This article aims to demonstrate how structured binding allows you to initialize multiple variables with individual elements of a structure, tuple, or array.

In C++17, you can use structured binding to access the individual elements, as shown below:

Under the hood, an anonymous variable with…

relationship between different objects

When a classes interacts with another class, a relationship develops between those two. This is called association. In an university, a student can learn from an instructor. We can model this relationship as follows.

The relationship can also show how many objects interact. This is called multiplicity. A student can learn from one or more instructors.

The model-view-delegate pattern is a variant of MVC pattern. The model has the data. The view is responsible for presenting data. Delegate is responsible for how data is presented. It basically decides how data is shown and modified.

In this article, I will write about ListModel and ListView.


ListModel contains a list of ListElement. Each ListElement contains a set of roles as properties. ListModel also has methods to access and modify each elements.

RAII is one of the patterns in C++ to manage resources.

Sometimes at some part of the program, we need to allocate some memory and later free it.

template <typename T, std::size_t N>
T* allocateMemory()
return new T[N];
template <typename T>
void freeMemory(T *p)
delete[] p;
int main()
int *p = allocateMemory<int, 10>();
// use p

return 0;

Disaster can happen when

  1. allocateMemory() is not called at all. Then the program will crash.
  2. freeMemory() is not called at all. There will be memory leak.
  3. freeMemory() is called twice from two different control paths or threads. It will cause double deletion and might crash.


This is a question which I was asked in a senior software engineer position for a Berlin based company.

SOLID is a set of 5 principles, which is followed to make maintainable systems.

S — Single Responsible Principle

O — Open-Closed Principle

L — Liskov Substitution Principle

I — Interface Segregation Principle

D-Dependency Inversion Principle

Single Responsibility Principle(SRP)

A class should have one and only one responsibility. And it should only have one reason to change.

The goal of SRP is to limit the impact of change. If a class has only one responsibility, there will only a few self…

Asit Dhal

C++11/14, Qt, Juce

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store