From my knowledge after a function is called in c++ its memory is deallocated for another variables. If it doesn't allocates to another variable then variable should have allocated memory dynamically. I'm confused how the function display() displays array values when it isn't allocated memory dynamically.
#include<iostream>
using namespace std;
void init_values(int arr[]){
for(int i=0;i<100;i++){
arr[i]=i;
}
}
void display(int arr[]){
for(int i=0;i<100;i++){
cout<<arr[i] << " ";
}
}
int main(){
int arr[100];
init_values(arr);
display(arr);
}
I expected the function displays garbage or will show an error. But it displayed the values correctly.