return bufDataIn[3];means "return the 4th element of the array bufDataIn", and in this case it leads to undefined behavior, since the size of this array is 3.
You can allocate memory for this new array in the body of your function and return a pointer to your first element:
BYTE* createArray(...)
{
BYTE* bufDataOut = new BYTE[3];
....
return bufDataOut;
}
Do not forget deletewhen you are done with it:
{
BYTE* myArray = createArray(...);
...
delete[] myArray;
}
, std::vector<BYTE> ;) , , .