CPP Comments

C++ comments updated

Comments are an essential part of a good source code. In this tutorial, we will learn about writing comments in C++ code. What is a Comment? Comments in programming are text notes that programmers include in their code to explain its purpose or make it easier to understand. They are not executed by the computer … Read more

Categories C++

How To Get the Type of a Variable in Cpp

Sometimes we need to determine the variable type at runtime in C++ code. This tutorial will discuss how to get the type of a variable in C++. The typeid operator allows us to determine the type of variable/object at runtime. The syntax of typeid operator Parameters: Typeid operator accepts one parameter : Type – Variable … Read more

Categories C++

Cppfront – A new Syntax for CPP

Cppfront feature image

C++ is a good programming language, it is used in performance-critical areas like gaming, multimedia processing, etc but some parts of CPP language syntax are still old-style (cpp1). Cppfront is an experimental compiler for C++ syntax2 (cpp2) by  Herb Sutter. My goal is to explore whether there’s a way we can evolve C++ itself to … Read more

Categories C++

Split Strings in C++

Splitting string into sub-strings is a common task in many applications. In this article, we will discuss various ways to split strings in C++. 1.Using the getline function The getline function can be used to split strings in C++. is : Extact string from istream object str : extracted line string delim : delimiter character … Read more

What is string::npos in C++?

In this article, we will discuss string::npos in C++. The std::string::npos is a static member constant. It is defined in the string (basic_string.h) header file. It is a static member constant with the maximum value representable by the type size_type. The type of size_type is unsigned integer however it is initialized as -1 but due … Read more

All About Pure Virtual Functions in C++

In this article, we will discuss pure virtual functions in C++ and usage with examples. Let’s dive into the definition of pure virtual function. So what is pure virtual function? A pure virtual function is a function, that must be overriden in the derived class need not to be defined A virtual function can be … Read more

Reading String From Input in C++

In this article, we will discuss different ways to read strings from input in C++. The cin object and getline function can be used to read strings. Using the cin to read string input In this example, we will use cin object to read strings. The cin is an istream object. Output Note that there … Read more

Virtual Destructors in CPP

In this article, we will discuss virtual destructors in CPP. Destructor is part of Resource Acquisition Is Initialization(RAII) programming idiom. The basic idea of RAII is constructor will acquire(allocate) resources and the destructor will release resources for a class. The most common example of a destructor is when the constructor uses new, and the destructor … Read more

Size of C++ classes

In this article, we will discuss the size of C++ classes. We will look into an empty class, a class with member function, a class with virtual functions, and a class with data members. We will be using a 64-bit machine to compile the test code. For a 64-bit machine, the pointer size is 8 … Read more

Shortest C++ Program

shortest c++ program

Have you ever thought about the shortest C++ program? In this article, we’ll look into the shortest C++ program. C++ is a compiled language. Firstly, the compiler processes the source code files and produces object files. The linker will combine these object files to yield an executable program. Let’s look into the smallest C++ program … Read more