I have defined a function to read an array of integers and return it as a pointer.
#include "stdafx.h"
#include <stdio.h>
const int size = 5;
int* getInput();
int main(int argc, _TCHAR* argv[])
{
int* a = getInput();
for(int i = 0; i < size; i++){
printf("%d \n", a[i]);
}
return 0;
}
int* getInput(){
int input[size];
for(int i = 0; i < size; i++){
scanf("%d", &input[i]);
}
return input;
}
The problem is that with the input of:
1
2
3
4
5
This program prints something like this:
1
5242692
1474139472
872394811
-2
I can't understand why this happens. Can anyone help me with this problem?