It works for me. Let us know what the error message is...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// Example program
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int A[2]={};
int T;
T=2;
A[1]=3;
A[2]=4;
cout<<A[T];
return 0;
}
You are getting An undefined error. The index you are trying to access is out of bounds.
In c++, array index starts from 0 . so, You can only access index from 0 to arraySize - 1In Your Case, your array contains two Elements: A[0] ==> first element A[1] ==> Second element