When we talk about C++ programming, functions and pointers are very important. A function is basically a series of steps packaged into a nice unit. A pointer is an object that refers to a value stored in memory. So why not just combine them and create something really useful! Function pointer is exactly what you think it is. A function pointer is a variable that stores the address of a function. We can call this function using the function pointer. But why would we want to do that? This looks like a roundabout way of doing things, right? What’s the purpose of having it in the first place? Continue reading “What’s The Use Of Function Pointers In C++?”

# Tag: Functions

# What Is Maximum Likelihood Estimation?

Let’s say you are trying to estimate the height of a group of people somewhere. If the group is small enough, you can just measure all of them and be done with it. But in real life, the groups are pretty large and you cannot measure each and every person. So we end up having a model which will estimate the height of a person. For example, if you are surveying a group of professional basketball players, you may have a model which will be centered around 6’7″ with a variance of a couple of inches. But how do we get this model in the first place? How do we know if this model is accurate enough to fit the entire group? Continue reading “What Is Maximum Likelihood Estimation?”

# Using Hash Function In C++ For User-Defined Classes

If you are a programmer, you must have heard the term “hash function”. In its most general form, a hash function projects a value from a set with many members to a value from a set with a fixed number of members. We basically convert the input into a different form by applying a transformation function. Hash functions map data of arbitrary length to data of a fixed length. The values returned by a hash function are called hash values. An interesting thing to note is that hash functions are not reversible. This means that you cannot recover the original data from hashed values. This property makes it one of the most useful data structures known to mankind. Hash functions are used extensively in internet security. In this post, we will talk about C++ STL and how to use hash functions with user defined classes. Continue reading “Using Hash Function In C++ For User-Defined Classes”

# How To Deal With Buffer Overflow

You must have encountered the word ‘buffer’ somewhere in your life. In everyday usage, buffer refers to something that acts as an intermediary between two things that don’t get along. It’s a shield which moderates the impact of one thing over the other. In the programming world, buffer refers to an area where we temporarily store data before moving it to another place. Perhaps the most famous example would be copy-paste. When you copy something, it is stored in the buffer until you paste it somewhere. This concept is used extensively while building software systems and it’s important to make sure that the buffer behaves nicely at all times. Now you might ask, what does buffer behavior refer to? Why would it not behave nicely at all times? Continue reading “How To Deal With Buffer Overflow”

# What Is Metaprogramming? – Part 2/2

This is a continuation of my previous blog post on metaprogramming. In the previous post, we saw why we need metaprogramming. In this post, we will see what exactly this whole metaprogramming is all about. In the world of programming, the basic problem is that any general-purpose programming language is that it has its own limitations. If the language doesn’t have a metaprogramming model that is as pleasant and expressive as the language itself, then it will eventually frustrate the user. Nobody can design the perfect language, we get that! The people who manage these languages don’t allow the users to extend the language in generic ways. Not a bad thing altogether! This is done because a lot of people end up extending it in too many different ways and it becomes one big potpourri of nastiness. Coming back to the topic at hand, how exactly do we understand metaprogramming? Continue reading “What Is Metaprogramming? – Part 2/2”

# What Is Metaprogramming? – Part 1/2

You know how people talk about creating machines that can create more machines by themselves? Well, we already have machines that can create other machines. The concept of metaprogramming is just the technical side of it. Metaprogramming is the process of writing programs that can create other programs. It is one of the most underused programming techniques. The good thing is that it allows programmers to minimize the number of lines of code to express a solution, or it gives programs greater flexibility to efficiently handle new situations without recompilation. If it’s so good, then why isn’t it used everywhere? Why do we need it? Before we jump into the details of metaprogramming, let’s understand why we would consider it in the first place. Continue reading “What Is Metaprogramming? – Part 1/2”

# Dissecting The Riemann Zeta Function

The Riemann Zeta function is an extremely important function in mathematics and physics. It is intimately related to very deep results surrounding the prime numbers. Now why would we want to care about prime numbers? Well, the entire concept of web security is built around prime numbers. Most of the algorithms for banking security, cryptography, networking, communication, etc are constructed using these prime numbers and the related theorems. The reason we do this is because of the inherently sporadic nature of prime numbers. You never know where the next one is going to appear on the number line! So what does that have to do with the Reimann zeta function? If prime numbers are random, what’s the point of looking into them? Continue reading “Dissecting The Riemann Zeta Function”

# What Is A Singularity?

You must have heard the term “singularity” being used in various contexts. We see it in mathematics, physics, circuit design, mechanics, fluid dynamics, etc. The word “singular” means something that is extraordinary, unique, and strange. When we talk about singularity in mathematics, we usually refer to the uniqueness of mathematical objects. In particular, singularities refer to the points where the mathematical objects are not well-behaved i.e. we can’t define them for those points. In higher mathematics, we usually define functions to explain the behavior of any system. These functions are the mathematical objects under consideration, and we will see how to understand their singularities. But why do we care about singularities? Is it just a mathematical concept or do we ever see it in real life? Continue reading “What Is A Singularity?”

# ifdef and ifndef

If you have worked on a large code base before, you would have seen ifdef and ifndef statements a lot of times. In fact, it is a good practice to have them wherever necessary. It just adds more robustness to your code and if you are working in a team, it helps you avoid weird compiler issues. The preprocessor directive #ifdef is used to define conditional groups of code at the preprocessor level. Based on a condition, a piece of code may or may not be included in the program. The body of this directive is usually termed controlled text. Continue reading “ifdef and ifndef”

# 1 + 2 + 3 + 4 + 5 + …. = -1/12

Wait a minute, what? That looks very very wrong. You must be wondering if the title is some horrendous typo, right? Well, let me assure you that it’s absolutely not! The sum of all natural numbers is equal to -1/12. This blog post is not just about mathematical trickery either. The equation in the title is actually a very important result used in theoretical physics, particularly in string theory. Now how can that be possible? Are physicists really that bad at mathematics? That can’t be it! What is the proof behind this? Do we ever encounter it in real life? Continue reading “1 + 2 + 3 + 4 + 5 + …. = -1/12”