Why the last printf in the main function doesn't print to the screen the value 10?
I know that in ANSI C, statically allocated matrix are arranged in memory in this way:
matrix: matrix[0][0], matrix[0][1],...,matrix[0][ColumnsDimension-1],matrix[1][0], etc
#include <stdio.h>
#include <stdlib.h>
#define dimRighe 20
#define dimColonne 30
int main()
{
int matrice[dimRighe][dimColonne];
int i,j;
for(i=0;i<dimRighe;i++)
for(j=0;j<dimColonne;j++)
matrice[i][j] = i+j;
matrice[0][3] = 10;
i = 0; j = 3;
printf("%d",*matrice[i*dimColonne+j]);
return 0;
}
Use *(matrice[i * dimColonne] + j) instead.
Why the last printf in the main function doesn't print to the screen the value 10?
Because matrice is an array of arrays ...
and matrice[whatever] is an array (which in most circunstances "decays" to a pointer to its first element)
and *matrice[whatever] is the contents of the first element of the array matrice[whatever].
In your code you have:
matrice[i*dimColonne+j]
Since i is 0 this evaluates to
matrice[j]
Since j is 3 this means
matrice[3]
When you print *matrice[3] that is equivalent to printing matrice[3][0] because matrice[3] is an array. And an array decays to a pointer to its first element.
But you don't want to do it this way at all. You should simply write matrice[i][j] and let the compiler do the work.
Change
printf("%d",*matrice[i*dimColonne+j]);
to simply be
printf("%d", matrice[i][j]);
if all you're worred about is printing out the right value. After all, that's how you assigned it.
If you're doing this as an exercise to understand how array subscripting works, then there are several things you need to remember.
First, except when it is the operand of the sizeof or unary & operators, or is a string literal being used to initialize another array in a declaration, an expression of type "N-element array of T" will be replaced with ("decay to") an expression of type "pointer to T", and its value will be the address of the first element of the array. The expression matrice is an array expression of type "20-element array of 30-element array of int"; in most circumstances, it will be converted to an expression of type "pointer to 30-element array of int", or int (*)[30]. Similarly, the expression matrice[i] is an expression of type "30-element array of int", and in most cirumstances it will be converted to an expression of type "pointer to int", or int *.
Here's a handy table to remember all of this:
Declaration: T a[N];
Expression Type Decays to
---------- ---- ---------
a T [N] T *
&a T (*)[N]
*a T
a[i] T
Declaration: T a[M][N];
Expression Type Decays to
---------- ---- ---------
a T [M][N] T (*)[N]
&a T (*)[M][N]
*a T [N] T *
a[i] T [N] T *
&a[i] T (*)[N]
*a[i] T
a[i][j] T
Second, the subscripting operation a[i] is defined as *(a + i); that is, you compute an address based on i number of elements (NOT BYTES) from the base address of your array and dereference the result. For example, if a is an array of int, then *(a + i) will give you the value of the i'th integer after a. If an is an array of struct foo, then *(a + i) will give you the value of the i'th struct after a. Pointer arithemtic always takes the size of the base type into account, so you don't need to worry about the number of bytes in the offset.
The same logic applies to multidimensional arrays, you just apply the rule recursively for each dimension:
a[i][j] == *(a[i] + j) == *(*(a + i) + j)
a[i][j][k] == *(a[i][j]+ k) == *(*(a[i] + j) + k) == *(*(*(a + i) + j) + k)
Note that you should almost never have to do these dereferences manually; a compiler knows what an array access looks like and can optimize code accordingly. Under the right circumstances, writing out the dereferences manually can result in slower code than using the subscript operator.
You can index into a 2-d array as if it were a 1-d array like so:
a[i*rows + j] = val;
but I wouldn't (the types of the expressions don't match up cleanly). Note that you multiply i by the number of rows, not columns.
You could also print it like this:
char *matrixAsByteArray = (char *) matrice;
char *startIntAddr = matrixAsByteArray + i * dimColonne * sizeof(int) + j * sizeof(int);
int outInt = *startIntAddr | *(startIntAddr + 1) << 8 | *(startIntAddr + 2) << 16 | *(startIntAddr + 3) << 24;
printf("%d", outInt);
What this does is first, it converts your matrix to an array of bytes, then, it gets the starting address of the integer you need, and then it reconstructs the integer from the first four bytes read from that address.
This is a bit overkill, but a fun solution to the problem.
Related
Here's the code that I am trying to work with.
int main(void) {
int array[2][5];
for (int ** p = array; p < array + 2; p++) {
*((*p) + 2) = 20;
}
for (int row = 0; row < 2; row++) {
for (int col = 0; col < 5; col++) {
printf("%d ", array[row][col]);
}
printf("\n");
}
return EXIT_SUCCESS;
}
And this is the output given out by the compiler.
main.c:11:21: warning: initialization of 'int **' from incompatible pointer type 'int (*)[5]' [-Wincompatible-pointer-types]
11 | for (int ** p = array; p < array + 2; p++) {
| ^~~~~
main.c:11:30: warning: comparison of distinct pointer types lacks a cast
11 | for (int ** p = array; p < array + 2; p++) {
| ^
main.exe
make: *** [Makefile:7: main] Error -1073741819
I clearly don't understand type casting when it comes to multidimensional arrays. It would really help if you could explain why this doesn't work.
Omitting the first for loop and doing things manually like this do seem to give out the intended result.
*((*array) + 2) = 20;
*(*(array + 1) + 2) = 20;
I can't get the hang of "int (*)[5]".
The type of array is int [2][5], an array of two arrays of 5 int.
When an array is used in an expression other than as the operand of sizeof, the operand of unary &, or as a string literal used to initialize an array, it is automatically converted to a pointer to its first element.
Since the type of array is int [2][5], the type of its first element is int [5], an array of 5 int. So the type of a pointer to its first element is int (*)[5], a pointer to an array of 5 int.
There is no rule that a pointer to an array is converted to a pointer to a pointer. So no further automatic conversion happens. The result of using array in an expression where it is automatically converted is an int (*)[5].
Therefore, p should be declared to be int (*)[5]:
for (int (*p)[5] = array; p < array + 2; p++)
A multi-dimensional array in C can be seen as an array of arrays. Each of the two top-level elements in array[2][5] is a one-dimensional array of 5 ints. Like any old array, array "decays" in most expressions to a pointer to its first element, that is, a pointer to an int[5]. A declaration for such a pointer would be int (*firstRow)[5] = array; (initializing it with the address to the first top-level element of array). The parentheses are necessary because the indexing operator [] has higher priority than the dereferencing operator *: int *arrayOf5Pointers[5]; would index first, and the result would be a pointer, so that it declares a real array (we can index it) whose elements in turn are pointers (we can dereference the result of the indexing). With (*firstRow)[5]; we indicate that we dereference first (the variable is a pointer) and only then index the result of the dereferencing (which must be an array).
The notation for the type of (*firstRow)[5]; (what you would use in a type cast) is, as always, the notation for a declaration without the identifier, hence int (*)[5]. That looks funny and perhaps ambiguous; but Kernighan/Richie said in their C book that the C grammar guarantees that there is only one valid position for an identifier in such a type notation. I believe them.
Your assignment int ** p = array is wrong: You cannot assign a (pointer to an array of 5 ints) to (a pointer to pointer to int). That is true even though you can legitimately access the first element of the two-dimensional array with e.g. int i = **array;: array decays to a pointer to its first element, that is, to a pointer to an array of 5 ints; the first dereferencing results in the actual array of 5 ints; which in turn decays to a pointer to its first int element; which is dereferenced with the second *.
The general takeaway here is: Pointers to arrays are rare and typically unnecessary. Simply index your 2-dimensional array in the normal fashion:
for(int row = 0; row < 2; row++) { array[row][2] = 20; }
or, better,
for(int row = 0; row < sizeof array/sizeof *array; row++) { array[row][2] = 20; }
The latter determines the number of top-level elements in the array by dividing its overall size in bytes by the size of its first element. The loop stays correct even if you change the size of array.
Let's say we have declared: int array[10][6]. As far as I understand, when you say array[i][j], it translates to *(((int *)array)+i*6+j). But, why does it work if array would be dynamically allocated because to access an element this would be needed: *(*(array+i)+j)? I don't understand why a[i][j] would work now if it is automatically translated like in the first case. Thanks.
Why does it work to access a dynamically allocated 2D array element with a[i][j]?
That's because pointer arithmetic and array indexing are same. Theexpression
array[i][j]
is equivalent to *(*(array + i) + j)). In this expression array converts to pointer to its first element and hence becomes of type int(*)[6], i.e. pointer to an array of 6 int. Adding i to array will increment it to i*sizeof(int[i]) bytes. Therefore, saying array[i][j] is translated to *(((int *)array)+i*6+j) is wrong.
So, dereferencing array + i will give an array of 6 int which further will decay to pointer to its first element array[i][0] having type int *. Therefore, array[i][j] is equivalent to *(&array[i][0] + j))
When array is allocated dynamically
int **array = malloc(sizeof(int*)*10);
for(int i =0; i < 10; i++)
array[i] = malloc(sizeof(int)*6);
then its element can also be accessed using array[i][j]. This expression is also equivalent to *(*(array + i) + j)). But, the difference here is array is of type int ** and adding i to it will increment it by i*sizeof(int*). Dereferencing array + i will give array[i] which is of type int * and hence array[i][j] is equivalent to *(&array[i][0] + j)).
That said, in both cases array + i increment it to its next element (which can either be of type int[6] or int *) and finally arithmetic is between int * (&array[i][j]) and int (j).
If you have a two-dimensional array like this
int a[M][N];
then in expressions arrays are implicitly converted to pointers to their first element.
So this expression
a
has type int ( * )[N] and points to the first "row" (element) of the two-dimensional array.
Expression
a + i
where i some intager in the range 0 - M - 1 point to i-th row of the array
Expression
*( i + i )
gives the row that is i-th element of the array.
You can write for example
printf( "%zu\n", sizeof( a[i] ) );
and the statement outputs a value that is equal to N * sizeof( int )
On the other hand if this expression
*( i + i )
is used in other context then as an operand of the sizeof operator then it in turn (as it is an array) is converted to pointer to its first element.
Thus expression
*( i + i )
is implicitly converted to pointer of type int * that points to the first element of the i-th row of the original array.
Expression
*( i + i ) + j
points to th j-th element of the i-th row of the array
As result expression
*( *( i + i ) + j )
is equivalent to
a[i][j]
If you dynamically allocated a two dimensional array the following way
int ( *a )[N] = malloc( sizeof( int[N][M] );
then you at once got the pointer of the same type and having the same value as the expression shown above for the two-dimensional array
a
So when you have initially a pointer then the step that implicitly converts a two-dimensional array to a pointer is simply skipped. But the net result will be the same.
If you allocated dynamically an array of pointers the following way
int **a = malloc( M * sizeof( int * ) );
for ( size_t i = 0; i < M; i++ ) a[i] = malloc( N * sizeof( int ) );
then a points to the first element of the dynamically alllocated first array.
a + i
gives the pointer to the i-th element of the array.
Expression
*( a + i )
gives the value stored in this element. This value is the address of the i-th allocated array in the loop aboth. It has type int *.
So
*( a + i ) + j
gives the pointer to the j-th element and at last
*( *( a + i ) + j )
is the unteger value stored in this element.
I am trying to get value from "second row" in multidimensional array. But I have some problems with that.
I thought that numbers are stored sequentialy in memory so tab[2][2] is stored same as tab[4]. But it seems that I was wrong.
This is what I tried:
int b[2][2] = {{111,222},{333,444}};
int i = 0;
for(;i < 100; i++)
printf("%d \n", **(b+i));
The problem is that I get only 111 and 333 as the result. There is no 222 or 444 in other 98 results. Why?
The problem is that **(b+i) doesn't do what you think it does. It evaluates to:
b[i][0]
As Matt McNabb noted,
**(b+i)
is equivalent to:
*(*(b+i)+0)
and since *(b+i) is equivalent to b[i], the expression as a whole can be seen as:
*(b[i]+0)
and hence:
b[i][0]
Since your array has only 2 rows, only the values of i for 0 and 1 are in bounds of the array (that's the 111 and 333). The rest was wildly out of bounds.
What you could do is:
#include <stdio.h>
int main(void)
{
int b[2][2] = { { 111, 222 }, { 333, 444 } };
int *base = &b[0][0];
for (int i = 0; i < 4; i++)
printf("%d: %d\n", i, base[i]);
return 0;
}
Output:
0: 111
1: 222
2: 333
3: 444
You can think of a two-dimensional array as a special form of a one-dimensional array. Your array holds 2 elements (!). (Each element happens to be an array of two elements, but let's ignore that for a sec.) Let's make the dimensions different so that we can distinguish them:
int arr2d[2][3] holds 2 elements (each being an array of 3 elements). The "primary index" is written first, that is if you have a one-dimensional array of 3 like int arr1d[3]and want to have an array of those with three elements like arr2d, you have to write arr2d[2][3]. You could arrange that with a typedef which makes it clear that all arrays in C are essentially 1-dimensional:
typedef int arr3IntT[3];
arr3IntT arr2d[2] = { {0,1,2}, {3,4,5} };
Now what does arr2d+i mean? arr2d, like any array, decays to a pointer to its first element (which is an array of 3 ints). arr2d+1 adds the offset of 1 of those elements to the address, so that like always the expression yields the address of the second element (which is the second array of 3 ints). Dereferencing it once like *(arr2d+1) yields that element, i.e. the one-dimensional sub-array of 3 ints. It decays to a pointer to its first element, i.e. a pointer to the first int in that second sub-array. Dereferencing that in the expression **(arr2d+1) yields that int, like always. To summarize: In your original code you iterate from sub-array to sub-array, always referencing the first of their elements, incidentally going out of bounds for i>1.
But principally you are right, elements of n-dimensional arrays in C are lying contiguously in memory, so you can access them one by one if you like to. You just have to index a pointer to int, not one to int[3]. Here is how: The expression arr2d decays to a pointer to its first element which is an array of 3 ints. Dereferencing that gives that first element, a one-dimensional array of 3 ints. Like all arrays, it decays to a pointer to its first element, an int, which is the very first element in the data:
#include<stdio.h>
int main()
{
int arr2d[2][3] = { {0,1,2}, {3,4,5} };
int *p_el1 = *arr2d;
int i, j;
// Sanity check by indexing 2-dimensionally
for(i=0; i<2; i++) for(j=0; j<3; j++) printf("%d\n", arr2d[i][j]);
// iterate the elements 1 by 1
for(i=0; i<3*2; i++) printf("%d\n", p_el1[i]);
}
A multidimensional array is not a fundamentally new type. It's an array type where the elements are themselves arrays. To quote the C99 standard §6.2.5 ¶20 (Types)
An array type describes a contiguously allocated nonempty set of
objects with a particular member object type, called the element type.
Array types are characterized by their element type and by the number
of elements in the array.
int b[2][2] = {{111, 222}, {333, 444}};
The above statement defines b to be an array of 2 elements where each element is the type int[2] - an array of 2 integers. It also initializes the array with the array initializer list. An array is implicitly converted to a pointer to its first element in some cases.
In the printf call, b decays to a pointer to its first element. Therefore, it's equivalent to &b[0] and has type int (*)[2] - a pointer to an array of 2 integers. Please note that it's undefined behaviour to access elements out of the bound of an array. Therefore, the for loop condition i < 100 is wrong. It should be i < 2. Now, let's try to demystify the expression **(b+i).
b -------------> pointer to a[0]
b + i ---------> pointer to a[i]
*(b + i) -----> a[i]
*(*(b + i)) ---> *(a[i]) ----> *(&(a[i])[0]) ----> a[i][0]
As noted, the elements of the array are themselves arrays. Therefore, a[i] is an array. Again, the array decays to a pointer to its first element, i.e., to &(a[i])[0]. Applying indirection operator * on this pointer gets us the value at that address which is a[i][0].
You can access the elements of the array through a pointer but the pointer type must be a pointer to element type of the array.
#include <stdio.h>
int main(void) {
int b[2][2] = {{111, 222}, {333, 444}};
int (*p)[2] = b;
// (sizeof b / sizeof b[0]) evaluates to
// the size of the array b
for(int i = 0; i < (sizeof b / sizeof b[0]); i++)
// (sizeof *p / sizeof (*p)[0]) evaluates to
// the size of element of the array which is
// itself an array.
for(int j = 0; j < (sizeof *p / sizeof (*p)[0]); j++)
printf("%d\n", *(*(p + i) + j));
return 0;
}
Here, the expression *(*(p + i) + j) can be decoded as
p ---------------> pointer to the first element of b, i.e., &b[0]
(p + i) ----------> pointer to b[i], i.e., &b[i]
*(p + i) ---------> the array element b[i] ---> decays to &(b[i])[0]
*(p + i) + j -----> &(b[i])[j]
*(*(p + i) + j) --> the element b[i][j]
Therefore, the expression *(*(p + i) + j) is equivalent to b[i][j]. In fact, the C99 standard §6.5.2.1 ¶2 says -
The definition of the subscript operator [] is that E1[E2] is
identical to (*((E1)+(E2)))
This means we have the following are equivalent with context to the above program -
*(*(p + i) + j)
// equivalent to
p[i][j]
// equivalent to
b[i][j]
// equivalent to
*(*(b + i) + j)
Please consider the following 2-D Array:
int array[2][2] = {
{1,2},
{3,4}
};
As per my understanding:
- 'array' represents the base address of the 2-D array (which is the same as address of the first element of the array, i.e array[0][0]).
The actual arrangement of a 2-D Array in memory is like a large 1-D Array only.
Now, I know that base address = array. Hence, I should be able to reach the Memory Block containing the element: array[0][0].
If I forget about the 2-D array thing & try to treat this array as a simple 1-D array:
array[0] = *(array+0) gives the base address of the first array & NOT the element array[0][0]. Why?
A 2-D array does not store any memory address (like an Array of Pointers).
If I know the base address, I must be able to access this memory as a linear 1- Dimensional Array.
Please help me clarify this doubt.
Thanks.
array[0] is a one-dimensional array. Its address is the same as the address of array and the same as the address of array[0][0]:
assert((void*)&array == (void*)&(array[0]));
assert((void*)&array == (void*)&(array[0][0]));
Since array[0] is an array, you can't assign it to a variable, nor pass it to a function (if you try that, you'll be passing a pointer to the first element instead). You can observe that it's an array by looking at (array[0])[0] and (array[0])[1] (the parentheses are redundant).
printf("%d %d\n", (array[0])[0], (array[0])[1]);
You can observe that its size is the size of 2 int objects.
printf("%z %z %z\n", sizeof(array), sizeof(array[0]), sizeof(array[0][0]));
Here's a diagram that represents the memory layout:
+-------------+-------------+-------------+-------------+
| 1 | 2 | 3 | 4 |
+-------------+-------------+-------------+-------------+
`array[0][0]' `array[0][1]' `array[1][0]' `array[1][1]'
`---------array[0]---------' `---------array[1]---------'
`-------------------------array-------------------------'
"Thou shalt not fear poynter arythmethyc"...
int array[2][2] = { { 1, 2}, { 3, 4 } };
int *ptr = (int *)&array[0][0];
int i;
for (i = 0; i < 4; i++) {
printf("%d\n", ptr[i]);
}
Why does this work? The C standard specifies that multidimensional arrays are contigous in memory. That means, how your 2D array is arranged is, with regards to the order of its elements, is something like
array[0][0]
array[0][1]
array[1][0]
array[1][1]
Of course, if you take the address of the array as a pointer-to-int (int *, let's name it ptr), then the addresses of the items are as follows:
ptr + 0 = &array[0][0]
ptr + 1 = &array[0][1]
ptr + 2 = &array[1][0]
ptr + 3 = &array[1][1]
And that's why it finally works.
The actual arrangement of a 2-D Array in memory is like a large 1-D Array only.
yes, the storage area is continuous just like 1D arrary. however the index method is a little different.
2-D[0][0] = 1-D[0]
2-D[0][1] = 1-D[1]
...
2-D[i][j] = 1-D[ i * rowsize + j]
...
If I forget about the 2-D array thing & try to treat this array as a simple 1-D array: array[0] = *(array+0) gives the base address of the first array & NOT the element array[0][0]. Why?
the *(array+0) means a pointer to a array. the first element index in such format should be *((*array+0)+0).
so finally it should be *(*array)
A 2-D array does not store any memory address (like an Array of Pointers).
of course, you can . for example ,
int * array[3][3] ={ null, };
If I know the base address, I must be able to access this memory as a linear 1- Dimensional Array.
use this formal 2-D[i][j] = 1-D[ i * rowsize + j]...
Arrays are not pointers.
In most circumstances1, an expression of type "N-element array of T" will be converted ("decay") to an expression of type "pointer to T", and the value of the expression will be the address of the first element of the array.
The type of the expression array is "2-element array of 2-element array of int". Per the rule above, this will decay to "pointer to 2-element array of int (int (*)[2]) in most circumstances. This means that the type of the expression *array (and by extension, *(array + 0) and array[0]) is "2-element array of int", which in turn will decay to type int *.
Thus, *(array + i) gives you the i'th 2-element array of int following array (i.e., the first 2-element array of int is at array[0] (*(array + 0)), and the second 2-element array of int is at array[1] (*(array + 1)).
If you want to treat array as a 1-dimensional array of int, you'll have to do some casting gymnastics along the lines of
int *p = (int *) array;
int x = p[0];
or
int x = *((int *) array + 0);
1. The exceptions are when the array expression is an operand of the sizeof or unary & operators, or is a string literal being used to initialize another array in a declaration.
I like H2CO3's answer. But you can also treat the pointer to the array as an incrementable variable like so:
int array[2][2] = { { 1, 2}, { 3, 4 } };
int *ptr = (int *)array;
int i;
for (i = 0; i < 4; i++)
{
printf("%d\n", *ptr);
ptr++;
}
the ++ operator works on pointers just fine. It will increment the pointer by one address of it's type, or size of int in this case.
Care must always be used with arrays in c, the following will compile just fine:
int array[2][2] = { { 1, 2}, { 3, 4 } };
int *ptr = (int *)array;
int i;
for (i = 0; i < 100; i++) //Note the 100
{
printf("%d\n", *ptr);
ptr++;
}
This will overflow the array. If you are writing to this you can corrupt other values in the program, including the i in the for loop and the address in the pointer itself.
i had a question in my program. When I pass the 3D int array CodedGreen to the function Green_Decode_Tree. An error message"invalid use of array with unspecified bounds" displayed. What is the mistake in my program? Thanks for your help.
for(i=0;i<256;i++){
for(j=0;j<256;j++){
Decode_Tree(green[0], CodedGreen,0,i,j);
}
}
void Green_Decode_Tree(node* tree, int code[][][], int num,int row,int col)
{
int i;
i=num;
if((tree->left == NULL) && (tree->right == NULL)){
fprintf(DecodGreen,"%s\n", tree->ch);
}
else
{
if(code[row][col][num]==1){
i++;
Green_Decode_Tree(tree->left,code,i,row,col);
}
else if (code[row][col][num]==0){
i++;
Green_Decode_Tree(tree->right,code,i,row,col);
}
}
}
i will reveal you a secret. 2d (and 3d) arrays are represented as liner memory arrays. when you have array NxM and access it like a[i][j] it is actually translated to a[i*M + j] as you might notice compiler must know M here to do this conversion, otherwise it will not be able to translate it. So thats what he asks. You must provide all except first sizes in array: int code[][M][N]
Remember that in most contexts, array expressions have their types implicitly converted ("decay") from "N-element array of T" to "pointer to T" and evaluate to the address of the first element. When you pass CodedGreen (type int [X][Y][Z]) to Green_Decode_Tree, what the function receives is a pointer value of type int (*)[Y][Z].
So your prototype for Green_Decode_Tree needs to be
void Green_Decode_Tree(node *tree, int (*code)[Y][Z], int num, int row, int col)
Note that in the context of a function parameter declaration, int *a is synonymous with int a[] (no size), so int (*code)[Y][Z] could also be written as int code[][Y][Z]. I prefer using pointer notation, since that's what the function actually receives, but either will work. Note that in your function you will subscript it as normal:
if (code[row][num][col] == 1)
since the subscript operator implicitly dereferences the pointer (i.e., code[row] == *(code+row)).
This may be helpful:
Declaration Expression Type Decays to
----------- ---------- ---- ---------
T a[X]; a T [X] T *
&a T (*)[X]
T b[X][Y]; b T [X][Y] T (*)[Y]
&b T (*)[X][Y]
b[i] T [Y] T *
&b[i] T (*)[Y]
T c[X][Y][Z]; c T [X][Y][Z] T (*)[Y][Z]
&c T (*)[X][Y][Z]
c[i] T [Y][Z] T (*)[Z]
&c[i] T (*)[Y][Z]
c[i][j] T [Z] T *
The expressions a, b, b[i], c, c[i], and c[i][j] are all array expressions, so their types will decay to pointer types in most contexts. The exceptions are when the array expressions are operands of the sizeof or address-of & operators (as is shown in the table), or when the array expression is a string literal being used to initialize another array in a declaration.