fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. // Initialize the array correctly
  5. int a[] = {1, 2, 3, 4, 5, 6, 7, 8};
  6. int *p;
  7. p = a; // Assign the address of the first element of the array to the pointer
  8.  
  9. printf("%d\n", p[5]); // Print the sixth element (6)
  10. printf("%d\n", p[0] + 1); // Print the first element + 1 (1 + 1 = 2)
  11. printf("%d\n", p[2] + 2); // Print the third element + 2 (3 + 2 = 5)
  12.  
  13. p = &a[3]; // Assign the address of the fourth element of the array to the pointer
  14. printf("%d\n", p[3] + 1); // Print the seventh element + 1 (7 + 1 = 8)
  15. printf("%d\n", p[4] + 1); // Print the eighth element + 1 (8 + 1 = 9)
  16.  
  17. return 0;
  18. }
  19.  
Success #stdin #stdout 0s 5272KB
stdin
Standard input is empty
stdout
6
2
5
8
9