Advertisement
fatman01923

Pointers for Multi Dimensional arrays. C(language)

May 22nd, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5.  
  6. int main(){
  7.     //Define the matrix, B[i][j] where i = # of rows
  8.     // where j = # of columns
  9.     int B[6][6] = {
  10.     {1,2,3,4,5,6} ,
  11.     {7,8,9,10,11,12} ,
  12.     {13,14,15,16,17,18} ,
  13.     {19,20,21,22,23,24} ,
  14.     {25,26,27,28,29,30} ,
  15.     {31,32,33,34,35,36}
  16.     };
  17.     printf("Values in the table\n");
  18.     for(int i=0;i<6;i++)//For i<6 change 6 to the number of n rows.
  19.     {
  20.         for(int j=0;j<6;j++)//For j<6 change 6 to the number of n coloumns.
  21.         {
  22.             printf("%d\t",B[i][j]);
  23.         }
  24.         printf("\n");
  25.     }
  26.     printf("\nAddresses\n");
  27.     for(int i=0;i<6;i++)//For i<6 change 6 to the number of n rows.
  28.     {
  29.         for(int j=0;j<6;j++)//For j<6 change 6 to the number of n coloumns.
  30.         {
  31.             printf("%d\t",&B[i][j]);
  32.         }
  33.         printf("\n");
  34.     }
  35.     //Here is the code you want to edit and get used to
  36.     //the various additions you can do to get different values.
  37.     printf("\nArithmatic\n");
  38.     printf("%d\n",&B[5][5]);
  39.     printf("%d\n",&B[0]+2);
  40.     printf("%d\n",&B[0]+10);
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement