Assuming you aren't going to later modify what maskArray points to, then the best/simplest solution is:
const int* maskArray;
if(conditional==true)
{
static const int myArray[9] = {0,1,0,1,-4,1,0,1,0};
maskArray = &myArray[0];
}
Static const works if you never plan to update the array, but if you're going to update it, you need a separate copy. This may be created either on the stack or on the heap. To create it on the stack:
int* maskArray;
int myArray[9] = {0,1,0,1,-4,1,0,1,0};
if(conditional==true)
{
maskArray = &myArray[0];
}
// when `myArray` goes out of scope, the pointer stored in maskArray will be useless! If a longer lifetime is needed, use the heap (see below).
To dynamically create new copies of the array on the heap, you need to allocate the memory using new[]. The advantage of this is that it can be kept around for as long as it's useful before you decide to delete it.
int* maskArray;
if(conditional==true)
{
maskArray = new int[9] {0,1,0,1,-4,1,0,1,0};
}
Remember to delete is later using delete[] maskArray!
(int[9]) {0,1,0,1,-4,1,0,1,0};is a C construct, it is not legal in C++ . Please confirm which language you are trying to use