C & C++

C & C++

Made by DeepSource

Misplaced array index in subscript/indexing expression CXX-C2019

Anti-pattern
Minor

Unusual array index syntax can lead to confusion and potential bugs in the code.

Using the correct array index syntax X[Y] ensures that the code is more readable and less prone to bugs. It is important to use the standard array index syntax to maintain clarity and consistency in the codebase.

Consider putting the index inside the square braces, while the array/pointer left of it.

Bad Practice

void f(int *X, int Y) {
  Y[X] = 0;
}

Recommended

void f(int *X, int Y) {
  X[Y] = 0;
}