Pointer to local variable
- by Radek Šimko
May I have any acces to local variable in different function? If may, how?
void replaceNumberAndPrint(int array[3]) {
printf("%i\n", array[1]);
printf("%i\n", array[1]);
}
int * getArray() {
int myArray[3] = {4, 65, 23};
return myArray;
}
int main() {
replaceNumberAndPrint(getArray());
}
The output of the piece of code above:
65
4202656
What am i doing wrong? What the "4202656" means??
Do I have to copy the whole array in the replaceNumberAndPrint() function to be able to access to it more than first times?