this my program to return array from function in c++
#include <iostream>
using namespace std;
int *pTest(){
static int a[] = {2,3,4,6,9};
return a;
}
int main(){
int *x;
x = pTest();
while(*x != NULL){
cout << *x++ << " ";
}
}
according to me output should be 2 3 4 6 9
but on my machine output is 2 3 4 6 9 1,
why there is an extra 1 in the output.
i am using codeblocks ,gcc 4.8.1
struct S {S(int);};and an array ofS?std::vectorfor dynamically sized orstd::arrayfor fixed size)static int a[] = {2,3,4,6,9,0};