Squaring numbers in an array
int size = sizeof(array)/sizeof(array[0]);

Just so you know, sizeof() returns size_t.
You can use a vector instead of an array. 

vector&lt;int&gt; data = {2,4,6,8,10};

Simplify squaring using std::transform() and use a lambda expression
    in place of a function object:




#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;functional&gt;

using std::cout;
using std::transform;
using std::vector;

int main()
{

    vector&lt;int&gt; data = {2,4,6,8,10};

    transform(data.begin(), data.end(), data.begin(), [](int x){return x*x;});


    for(auto i : data)
        cout &lt;&lt; i &lt;&lt; " ";

}