C++, memset a double array failed : I am new to C, and I want to declare a doube type array dynamicly, so here is my code

    void function(int length, ...)
    {
        [snippet]
        double * a = (double *)malloc(sizeof(double) * length);
        memset(a, 1, sizeof(double) * length);
        for (int i = 0; i < length; i ++)
        {
            cout << a[i] << endl;
        }
    
        [snippet]
    }

When I set the length to 2 and the code did not print all 1s. It just print the following outputs.

    7.7486e-304
    7.7486e-304

So, what should I do to fix it? Thank you!
