This is my test code
#include <QCoreApplication>
#include <QDebug>
void fillData(unsigned char *data){
data = new unsigned char[10];
for (int i = 0; i < 10; i++){
data[i] = static_cast<unsigned char>(i);
}
qDebug() << "Returning wiht non null data?" << (data == nullptr);
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
unsigned char *data = nullptr;
qDebug() << "Is data null" << (data == nullptr);
fillData(data);
qDebug() << "Is data null" << (data == nullptr);
return a.exec();
}
I need to fill a pointer to array of bytes inside a fucntion and I was noting in my application that I kept getting null. So I wrote this MWE. It reproduces the problem as the output for this program is
Is data null true
Returning wiht non null data? false
Is data null true
When I would expect the theird question to return false. I can't figure out what I'm doing wrong.