computeCube function is correct, but the main function has a problem. Explain why it doesn't work and show how to fix it. Your fix must be to the main function only; you must not change computeCube.

void computeCube(int n, int* ncubed)
    {
        *ncubed = n * n * n;
    }

    int main()
    {
        int* ptr;
        computeCube(5, ptr);
        cout << "Five cubed is " << *ptr << endl;
    }

Thanks

And what was your answer? We're not here to do your homework for you.

p.s. Use code tags for code. It's not like Daniweb doesn't slap you in the face with instructions each time you post.
p.p.s. At least this question is solvable, unlike your other one.

how about you give it some thought, first?

i know that I need to change the main function to:

int main()
    {
        int ptr;
        computeCube(5, &ptr);
        cout << "Five cubed is " << ptr << endl;
    }

but I don't understand why i need to do that.. Is that because i cannot pass a pointer without initialized it first?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.