C - Two-dimensional arrays and pointers

Description

Two-dimensional arrays and pointers

Demo

#include <stdio.h>

int main(void)
{
  char matrix[3][3] = {
    { '1','2','3' },
      { '4','5','6' },
      { '7','8','9' }
  };//from ww  w.  j av a2s  .c om

  printf("address of matrix        : %p\n", matrix);
  printf("address of matrix[0][0]  : %p\n", &matrix[0][0]);
  printf("value of matrix[0]       : %p\n", matrix[0]);
  return 0;
}

Result

Consider the expressions:

matrix
matrix[0]
&matrix[0][0]

These all have the same value:

matrix is the address of a two-dimensional array of char elements, 
matrix[0] is the address of a one-dimensional array of char elements that is a subarray of matrix, 
&matrix[0][0] is the address of an array element of type char. 

Related Topic