Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- a_way_to_access_matrix_elements.c
- Accessing Matrix Elements by Using Array Name as a Pointer
- http://ecomputernotes.com/what-is-c/function-a-pointer/accessing-matrix-elements
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- https://www.facebook.com/dmilicev
- */
- #include <stdio.h>
- #define N 3
- int main(void)
- {
- int i,j;
- //int a[N][N] = {10,20,30,40,50,60,70,80,90};
- int a[N][N] = {1,2,3,4,5,6,7,8,9};
- printf("\n");
- for(i=0;i<N;i++)
- {
- for(j=0;j<N;j++)
- printf(" %d ", a[i][j] );
- printf("\n");
- }
- printf("\n");
- for(i=0;i<N*N;i++)
- printf(" %d ", *(*a + i) );
- printf("\n");
- //printf("\n %d \n", *(1*N+1) );
- //printf("\n %d \n", **(1*N+1) );
- //printf("\n %d \n", **(a+1*N+1) );
- printf("\n %d \n", *(*(a+1)+1) );
- printf("\n %d \n", *(*(a)) );
- printf("\n %d \n", *(*(a+1)) );
- printf("\n %d \n", *(*(a+1)+1) );
- return 0;
- } // main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement