#include  <iostream>
using namespace std;
int *GetSquare(int x)
{
    int y = x;
    y = y * y;
    return &y;
}
int main()
{
    const int n = 4;
    int *p[n];
    for (int j = 0; j < 2; ++j)
    {
        p[2 * j + 1] = new int[2];
        for (int i = 0; i < 2; ++i)
            p[2 * j + 1][i] = 2 * j + 1;
    }
    p[0] = GetSquare(2);
    p[2] = GetSquare(4);
    for (int j = 0; j < n; ++j)
    {
        for (int i = 0; i < 1; ++i)
            cout << p[j][i] << " ";
        cout << endl;
    }
    return 0;
}
When I dry run this code I get the output "4 1 16 3". while in the compiler i get "16 1 3 3" theres no way the in which i can find the first output to be 16. What is wrong with my code?
 
     
     
    