array 2d to 1d

C++
 int array[width * height];

 int SetElement(int row, int col, int value)
 {
    array[width * row + col] = value;  
 }
Source

Also in C++: