Advertisement
dmilicev

a_way_to_access_matrix_elements.c

Jan 27th, 2020
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. /*
  2.  
  3.     a_way_to_access_matrix_elements.c
  4.  
  5.     Accessing Matrix Elements by Using Array Name as a Pointer
  6.     http://ecomputernotes.com/what-is-c/function-a-pointer/accessing-matrix-elements
  7.  
  8.  
  9.     You can find all my C programs at Dragan Milicev's pastebin:
  10.  
  11.     https://pastebin.com/u/dmilicev
  12.  
  13.     https://www.facebook.com/dmilicev
  14.  
  15. */
  16.  
  17. #include <stdio.h>
  18.  
  19. #define N 3
  20.  
  21. int main(void)
  22. {
  23.     int i,j;
  24.     //int a[N][N] = {10,20,30,40,50,60,70,80,90};
  25.     int a[N][N] = {1,2,3,4,5,6,7,8,9};
  26.  
  27.     printf("\n");
  28.  
  29.     for(i=0;i<N;i++)
  30.     {
  31.         for(j=0;j<N;j++)
  32.             printf(" %d ", a[i][j] );
  33.  
  34.         printf("\n");
  35.     }
  36.  
  37.     printf("\n");
  38.  
  39.     for(i=0;i<N*N;i++)
  40.         printf(" %d ", *(*a + i) );
  41.  
  42.     printf("\n");
  43.  
  44.     //printf("\n %d \n", *(1*N+1) );
  45.     //printf("\n %d \n", **(1*N+1) );
  46.     //printf("\n %d \n", **(a+1*N+1) );
  47.     printf("\n %d \n", *(*(a+1)+1) );
  48.  
  49.     printf("\n %d \n", *(*(a)) );
  50.     printf("\n %d \n", *(*(a+1)) );
  51.     printf("\n %d \n", *(*(a+1)+1) );
  52.  
  53.  
  54.     return 0;
  55.  
  56. } // main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement