Introduction The distinction between regular and static variables in C++ is a such a confusing topic for many beginners including students and programers. In this short article, I am going to provide an brief explanation and hopefully remove the ambiguity. …

# Tag Archives: Cpp

## Amicable Numbers

Amicable Numbers Definition Two positive integer numbers (m, n) are amicable if the sum of the proper divisors of (m) is equal to (n) and the sum of the proper divisors of (n) is equal to (m). A proper divisor …

## Matlab Simple mex Example

Matlab mex functions can be used to extend Matlab functionality or to improve performance by using compiled code as opposed to interpreted matlab syntax. Using mex functions is explained in many places on the web however the following is a …

## Copy String C++

Problem Write a C++ function to copy an existing string. Do not use built in functions. Solution This is a straight forward question and to my surprise I was asked this question in a site interview. If you are not …

## Row Major and Column Major in 2D Array

Problem Given a one dimensional integer array of 9 elements. Write a function to map the array into a row major 3×3 two dimensional array Solution If you are familiar with 3D graphics API like DirectX or OpenGL they store …

## Copy Constructor vs Assignment Operator in C++

Question In C++ what is the difference between copy constructor and assignment operator. If they are created for you by default then why do we need to create them in the first place. Assignment operator vs copy constructor Copy constructors …

## Counting by 2’s

Problem Write a C++ program to count the number of 2’s between 0 and (n) where (n) is a positive integer. Solution We need two loops, one goes from 0 to n and the other one examines the number digit …