Advertisement
obernardovieira

Print all 2D matrix values using a pointer

Jan 6th, 2016
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.28 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. struct abc {
  4.     int n;
  5. };
  6.  
  7.  
  8. int main() {
  9.  
  10.     struct abc n[5][2];
  11.     struct abc *p = &n[0][0];
  12.     int x;
  13.  
  14.     for (x = 0; x < 5; x++) {
  15.         n[x][0].n = x;
  16.         n[x][1].n = (x * 3);
  17.     }
  18.  
  19.     for (; p < (&n[0][0] + 10); p++) {
  20.         printf("-> %d\n", p->n);
  21.     }
  22.  
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement