Is this function safe?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <iostream>
using namespace std;
const char * func(int a) {
const char *p = "test";
return p;
}
int main() {
const char *p = func(1);
cout << p;
return 0;
}
|
will [p] always point to "test"?
Yes, a string literal is an array with static storage duration. It will exist until program termination.
Yes , it will ...
Topic archived. No new replies allowed.