fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int arr[3] = {1, 2, 3};
  5. int *p = arr; // 配列の先頭アドレスをポインタに代入
  6.  
  7. // 配列とポインタの操作例
  8. printf("arr[0] の値: %d\n", arr[0]);
  9. printf("p[0] の値: %d\n", p[0]); // p は arr の先頭要素を指すので同じ
  10. printf("*(p + 1) の値: %d\n", *(p + 1)); // 配列の 2 番目の要素
  11.  
  12. return 0;
  13. }
  14.  
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
arr[0] の値: 1
p[0] の値: 1
*(p + 1) の値: 2