So, for example i have this function:
char* retCharPtr(void) {
char data[15] {"Data is here"};
return data; }
And
char* retCharPtr1(void) {
char *data = new char[15];
strcat(data, "Data is here");
return data; }
Please explain where the data array will be placed if std::cout << retCharPtr1();
,
and what if std::cout << retCharPtr();
?
And in general, where do the values of variables go when functions return their status (int
) and it is not stored anywhere. Are these 4 bytes occupied during the full execution of the program?
I need the function to return an array for cout
, without the next call delete
, and leaks in memory.