Well, you need to pass the row size and the number of rows:
double doSomethingWithACol(double *matrix, size_t colID, size_t rowSize, size_t nRows);
Now you can use the fact that the matrix [i] [j] = matrix + i * rowSize + j;
Alternatively, you can also use the following signature:
double doSomethingWithACol(double *colPtr, size_t rowSize, size_t nRows);
Here you will need to pass a pointer to the first element of the column that you want to process, instead of a pointer to the first row.
Code example: This code summarizes the elements in the second column (compile with gcc -o main -Wall -Wextra -pedantic -std = c99 test.c):
#include <stdio.h> #include <stdlib.h> double colSum1(double *matrix, size_t colID, size_t rowSize, size_t nRows) { double *c = NULL, *end = matrix + colID + (nRows * rowSize); double sum = 0; for (c = matrix + colID; c < end; c += rowSize) { sum += *c; } return sum; } double colSum2(double *colPtr, size_t rowSize, size_t nRows) { double *end = colPtr + (nRows * rowSize); double sum = 0; for (; colPtr < end; colPtr += rowSize) { sum += *colPtr; } return sum; } int main(void) { double matrix[4][3] = { {0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {9, 10, 11} }; printf("%f\n", colSum1(*matrix, 1, 3, 4)); printf("%f\n", colSum2(&matrix[0][1], 3, 4)); printf("%f\n", colSum2(matrix[0] + 1, 3, 4)); return EXIT_SUCCESS; }