0

A have a function that takes in "int const * const data" as one of its arguments, and I have no idea what that means. I was expecting this function to take in an array, so I feel like this is an array, but I have no idea how. The lack of a comma is throwing me off. This is one argument.

EDIT: Ok, I didn't realize const was a keyword. Is there anyway that this points to an array? Because I'm expecting an array.

RothX
  • 265
  • 1
  • 2
  • 13

2 Answers2

2

Two means :

  1. The pointer is constant.
  2. The data (that the pointer pointing to ) is constant.
everettjf
  • 116
  • 2
  • 8
2

const is a keyword that applies to the argument on the left (or on the right if there's nothing left on the left) and denotes immutability (const-ness).

  • int const* -- pointer to an immutable (const) int (you can't use this pointer to mutate the int)

  • int const*const -- immutable pointer to an immutable int

Petr Skocik
  • 58,047
  • 6
  • 95
  • 142
  • Thank you, but is it possible that there is an array involved? I'm expecting this function to take in an array. – RothX Feb 19 '17 at 00:15
  • 1
    There are no genuine array parameters in C. Arrays passed through parameters are translated to pointers to the first element of the array. `int const*const` may well represent an `int` array. – Petr Skocik Feb 19 '17 at 00:18
  • I see. So how can I access other elements besides the first in the array? – RothX Feb 19 '17 at 00:21
  • You can treat the pointer as if it was an array and do array subscripting (http://port70.net/~nsz/c/c11/n1570.html#6.5.2.1) on it with: `pointer_to_first[index] == array[index]`. – Petr Skocik Feb 19 '17 at 00:25