I am not sure where is the dangling pointer here, i mean its an array not a pointer. it was in my exam and the answer was a dangling pointer? i am really confused i thought that a dangling pointer happens when a pointer is pointing outside and array scope ?
#include <iostream>
using namespace std;
int * f (int n) {
int a[10];
for (int i = 0; i < 10; i++)
a[i] = i*n;
return a;
}
void main() {
int j, k;
int * p;
j = 12;
p = f(j);
for (k = 0; k < 10; k++) {
cout << p[k];
}
cout << endl;
}