Q: Different Output in Visual Studio 2012 and c++11 The Following code produces different output in Visual Studio 2012 and c++11.
Problem:
http://www.codechef.com/FEB14/problems/SUBMIN
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray.
In this problem, a subarray is defined as a sequence of continuous elements Ai, Ai+1, ..., Aj where 0 ≤ i ≤ j ≤ N−1. The function foo, when applied to an array, returns the minimum of all the elements in the array.
For example, foo returns 5 when it is applied to the array [7, 5, 10, 7, 5, 8]. Please note that the subarrays Ai, Ai+1, ..., Aj and Ak, Ak+1, ..., Al are different if and only if i ≠ k or j ≠ l in this problem.
Input
The first line of input contains N, denoting the size of the array. The next line contains N space separated integers A0, A1, ..., AN−1, denoting the array. Then the next line contains Q, denoting the number of queries. Each query consists of one integer per line, denoting K.
Output
For each query, print the required number of subarrays.
Input:

5
4 1 2 3 4
4
3
4
6

1
Output in VS2012 and gcc 4.3.2 is
2
2
0
8

While the output in gcc 4.8.1 and c++11 is:
2
2
0
24

http://ideone.com/DUp72c
http://ideone.com/kFTlNe
Code:
int main() {

    map <int, vector<int> >b;
    int  arr[51], n;
    int ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
         cin >> arr[i];
         b[arr[i]].push_back(i);
    }
    int q, query, pos, l1, l2, vlength;
    cin >> q;
    while (q--)
    {
        ans = 0, l1 = 0, l2 = 0;
        cin >> query;
        vlength = b[query].size();
        int t = 0, c = 0;
        while (t < vlength){
            c = 1;
            for (size_t i = b[query].at(t) + 1; (i<n) && (arr[i] >= query); i++)
                if (arr[i] == query)
                {
                    c++;
                }

            for (size_t i = 0; i < c; i++)
            {
                l2 = 0;
                for (size_t k = b[query].at(t + i) - 1; (k >= 0) && (arr[k] > query); k--)
                    l2++;


                for (size_t j = i; j < c; j++)
                {
                    l1 = 0;
                    for (size_t m = b[query].at(t + j) + 1; (m<n) && (arr[m] > query); m++)
                        l1++;

                    ans += (l1 + 1)*(l2 + 1);
                }
            }
            t += c;

        }

        cout << ans << endl;


    }
    return 0;

}


A: This is due to subscript out of range. Double check by changing 
int arr[51];

to
array<int, 51> arr; 

You should get the assertion error. I suspect different output is a result of different compiler behavior on handling array index out of bound, in one of the case assigning arr[i] where i>50 is changing value of some other variable.
