My doubt is regarding a simple array question

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
ll n;
cin>>n;
ll a[n];
for(int i=1;i<=n;i++)
cin>>a[i];

sort(a,a+n);
cout<<a[n];

return 0;

}

what’s problem with this code it’s not passing your scale

@jindalkshitij21 Hey kshitij jindal, in Array index starts with 0. so loop goes like this
for(int i=0 ; i<n ; i++)

In cout << a[n] you are accessing the index which is not part of that array.
because index can be accessible from (0 to n-1).

Below link is for basic array operations.
code Link : https://ide.codingblocks.com/s/82075

Please feel free to ask if you are not understanding this thing.

@jindalkshitij21 Hey kshitij jindal, if your query is resolved. Please mark this doubt as resolved and if you have any query then tell me, I am happy to help you out.