masjoox

Tugas Pointer Sesi 12

Dec 29th, 2021
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. 1. Coding Tugas 1
  2. #include <stdio.h>
  3. #define SIZE 4
  4.  
  5. int main() {
  6. int a[][SIZE] = {{0,1,2,3}, {4,5,6}, {7,8,9,10} };
  7. int *p = &a[0][0];
  8. int *q = a[0];
  9. int *r = a[1];
  10. int *s = a[2];
  11. printf("%d ", *(p + SIZE + 1) );
  12. printf("%d ", p[SIZE + 1] );
  13. printf("%d ", p[2 * SIZE + 1] );
  14. printf("%d ", *(q + 2 * SIZE + 2) );
  15. printf("%d ", *r );
  16. printf("%d ", *(r - 2) );
  17. printf("%d\n", s[3] );
  18. return 0;
  19. }
  20.  
  21. 2. Coding Tugas 2
  22. #include <stdio.h>
  23.  
  24. int x = 2, y;
  25. void misteri(int a, int *b) {
  26. a = 2*x; *b = y; y = a;
  27. }
  28. int main() {
  29. x = 5; y = 7;
  30. misteri(y, &x);
  31. printf("%d %d\n", x, y);
  32. return 0;
  33. }
  34.  
  35. 3. Coding Tugas 3
  36. #include <stdio.h>
  37. #define N 10
  38. void what(int *b, int n) {
  39. if (n) {
  40. printf("%d ", *b++);
  41. what(&b[0], n-1);
  42. }
  43. }
  44. int main() {
  45. int x[N]={10, 20, 30, 40, 50};
  46. what(x, 5);
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment