I am not getting any of bounds errors or segmentation fault, and I do see from people's comments that this is common. But is there a way to get the compiler to issue an error instead of opening my program to possible undefined behavior?
#include <iostream>
#define MAX 10
int main(void){
    int A[MAX] = {9, 3, 9, 3, 9, 3, 0, 0, 9, 3};
    int C[10];
    int B[MAX] = {0};
    for (int i = 0; i < 10; i++)    C[i] = 0;
    //  increment count of buckets containing this digit accordingly
    for (int i = 0; i < MAX; i++)   C[A[i]] =  C[A[i]] + 1;
    //  count all count <= the current bucket to determine the correct index
    for (int i = 1; i < 10; i++)    C[i] = C[i] + C[i-1];
    //  copy the correct array element to output array B and decrement C array accordingly
    for (int i = MAX-1; i >= 0; i--){
        B[C[A[i]]] = A[i];
        C[A[i]] = C[A[i]]-1;
    }
    std::cout << "\nSorted array = ";
    for (int i = 1; i <= MAX; i++)  std::cout << " " << B[i] << " ";
    std::cout << "\n";
    return 0;
}
 
    