Algorithm to multiply two matrices #include &lt;iostream&gt;
#include &lt;vector&gt;


void function(std::vector&lt;std::vector&lt;int&gt;&gt;&amp; matrix1, const std::vector&lt;std::vector&lt;int&gt;&gt;&amp; matrix2)
{
    std::vector&lt;std::vector&lt;int&gt;&gt; matrix(matrix1.size(), std::vector&lt;int&gt;(matrix1.size()));
    int result = 0;
    int column = 0;
    if (matrix1.size() == matrix2.at(0).size() &amp;&amp; matrix1.at(0).size() == matrix2.size())
    {
        for (int i = 0; i &lt; matrix1.size(); ++i)
        {
            for (int j = 0; j &lt; matrix1.at(0).size(); ++j)
            {
                result += matrix1.at(i).at(j) * matrix2.at(j).at(column);
            }
            matrix.at(i).at(column) = result;
            if (column != matrix1.size() - 1)
            {
                --i;
                ++column;
            }
            else
                column = 0;
            result = 0;
        }
    }
    matrix1 = matrix;
}
int main()
{
    std::vector&lt;std::vector&lt;int&gt;&gt; matrix1{ {1,0,2}, {-1,3,1} };
    std::vector&lt;std::vector&lt;int&gt;&gt; matrix2{ {3,1}, {2,1}, {1,0} };
    function(matrix2, matrix1);
}


The function (i.e. function) multiplies two matrix variables and changes the first parameter(i.e. matrix1). Is it possible to improve my algorithm? 

I know that I can change variable names, but that isn't important. Its only an example. Maybe I can avoid two variable ints? I think that I always must create helper variables (matrix).
Well, first you should create your own class for matrices. Your current ad-hoc representation is inefficient and lacks abstraction.
Options include:


Row-major or column-major.
Restricted to specific dimensions / square matrices.
Using an array of pointers to rows/colums or explicit mapping of coordinates to ids.

Is there a reason you insist that the result-matrix should be square? Seems gratuitious.
There's no advantage to modifying the first input instead of returning a new matrix. So, make both arguments constant and return the result instead.
If you don't need an object any longer after copying it, might moving be more appropriate, as it's potentially more efficient and less likely to throw?