May I have any access to a local variable in a different function? If so, how?
void replaceNumberAndPrint(int array[3]) {
printf("%i
", array[1]);
printf("%i
", 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 does the "4202656" mean?
Do I have to copy the whole array in the replaceNumberAndPrint()
function to be able to access it more than the first time?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…