I'm a newbie and started to code couple of days ago. So today started with array and have some doubts. I'm reading a array by taking input from user and displaying it everything s running fine but on ouput screen I'm having a garbage value and dont know why. Please help me.
#include <iostream>
using namespace std;
int main(){
int number;
cout<<"Enter a array_size"<<endl;
cin>>number;
//Reading and printing array
int array[number];
int i=1;
while(i<=number){
cin>>array[i];
i++;
}
//printing array
int j=0;
while(j<=number){
cout<<array[j]<<endl;
j++;
}
}
Expected output: Reading from user: 3
1
2
3
//displaying
1
2
3
Actual result: Reading from user: 3
1
2
3
16
1
2
3
Why 16 is showing?