0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

st3.c the C puzzle book

Posted at
st3.c
#include "defs.h"

struct S1 {
        char *s;
        struct S1 *s1p;
};

void swap(struct S1 *p1, struct S1 *p2)
{
        char *temp = p1->s;
        p1->s = p2->s;
        p2->s = temp;
}


int main()
{
        static struct S1 a[] = {
                { "abcd", a+1 },
                { "efgh", a+2 },
                { "ijkl", a+3 }
        };

        struct S1 *p[3];
        int i;

        for( i=0; i<3; i++) p[i] = a[i].s1p;
        PRINT3(s, p[0]->s, (*p)->s, (**p).s);

        swap(*p, a);
        PRINT3(s, p[0]->s, (*p)->s, (*p)->s1p->s);

        swap(p[0], p[0]->s1p);
        PRINT3(s, p[0]->s, (*++p[0]).s, ++(*++(*p)->s1p).s);
}
p[0]->s = efgh  (*p)->s = efgh  (**p).s = efgh
p[0]->s = abcd  (*p)->s = abcd  (*p)->s1p->s = ijkl
Segmentation fault (core dumped)
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?