Help me in solving ARRY4V2 problem

My issue

the array here we take 3 as per requirement but after taking 4 it will show us a right ans . why?

My code

#include <bits/stdc++.h>
using namespace std;

int main() {

  string week[3] = {"Monday", "Tuesday", "Wednesday", "Thursday" };
  cout << week[ 2 ] << endl;
  cout << week[ 3 ];

  return 0;
}

Learning course: Learn C++
Problem Link: CodeChef: Practical coding for everyone

It is because week[3] will declare spaces up to 3 strings i.e. 0,1 and 2 but week[4] will declare spaces up to 4 strings indexing 0,1,2 and 3

1 Like

Thanks