-1

私のコードは次のようなものです:

struct a{
           ....
           ....
           };
    struct a c[MAXNODES];

    struct b{
           int k;
           struct a *p;
           };
    struct b d[MAXNODES];

したがって、ポインタにアクセスする必要がある場合struct astruct b、間接演算子を使用する必要があります。

some_variable=*(d.[i-1].p);
4

1 に答える 1

1

したがって、2 つの構造体があり、一方が他方のインスタンスへのポインターを保持します。

typedef struct a {
    int i;
} A;

typedef struct b {
    A *pA;
} B;

次に、どこかに、インスタンスがstruct a存在する構造の配列があります。

A arr[10];

B b;
b.pA = &arr[0]; // makes b.pA to point to the address of first element of arr
b.pA->i = 2;    // equivalent to (*b.pA).i = 2;

A a = *b.pA;    // creates a copy of an element that b.pA points to
A* pA = b.pA;   // stores the reference (copies the pointer)
于 2013-02-09T21:35:07.797 に答える