Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

const for array size expressions on argument

I have the following C code example:

int f(const int farg[const 5])
{
}

What does the additional const for the array size do? And what is the difference when I omit the const there?

like image 925
Kolja Avatar asked Jul 08 '14 08:07

Kolja


1 Answers

int d(const int darg[5])

Means darg is a pointer to const int.

int e(int earg[const 5])

Means earg is a const pointer to int. This is a c99 feature. T A[qualifier-list e] is equivalent as T * qualifier-list A in the parameter declaration.

And of course (from above):

int f(const int farg[const 5])

Means farg is a const pointer to const int.

like image 176
ouah Avatar answered Oct 06 '22 02:10

ouah