0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Pointers and Arrays 2: Array of Pointer, The C Puzzle Book p.55

Last updated at Posted at 2025-06-11

#include "defs.h"

int a[] = {0, 1, 2, 3, 4};
int *p[] = {a, a + 1, a + 2, a + 3, a + 4};
int **pp = p;

int main(void)
{
// a はポインタ(配列の先頭アドレス)、*a は int
PR(p, a); PRINT1(d, *a);

    // p はポインタ配列の先頭アドレス、*p は int*、**p は int
    PR(p, p); PR(p, *p); PRINT1(d, **p);

    // pp は int**、*pp は int*、**pp は int
    PR(p, pp); PR(p, *pp); PRINT1(d, **pp);

    NL;

    // それぞれインクリメント後の差分、値の表示
    pp++; PRINT3(d, pp - p, *pp - a, **pp);// W: format specifies type 'int' but the argument has type 'long' [-Wformat]
    pp++; PRINT3(d, pp - p, *pp - a, **pp);// W: format specifies type 'int' but the argument has type 'long' [-Wformat]
    ++pp; PRINT3(d, pp - p, *pp - a, **pp);// W: format specifies type 'int' but the argument has type 'long' [-Wformat]
    ++*pp; PRINT3(d, pp - p, *pp - a, **pp);//W: format specifies type 'int' but the argument has type 'long' [-Wformat]

    NL;

    // 再初期化
    pp = p;
    (void)**pp++; PRINT3(d, pp - p, *pp - a, **pp);// W: format specifies type 'int' but the argument has type 'long' [-Wformat]
    (void)*++*pp; PRINT3(d, pp - p, *pp - a, **pp);// W: format specifies type 'int' but the argument has type 'long' [-Wformat]
    ++**pp; PRINT3(d, pp - p, *pp - a, **pp);//       W: format specifies type 'int' but the argument has type 'long' [-Wformat]

    return 0;

}

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?