#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct XXX {
struct XXX* next;
int val;
};
struct XXX* create(int val)
{
struct XXX* data;
data
= (struct XXX
*) malloc(sizeof (struct XXX
)); data->next = NULL;
data->val = val;
return data;
}
void add_last(struct XXX* data, int val)
{
while (data->next != NULL) {
data = data->next;
}
data->next = create(val);
}
int main(void)
{
struct XXX* data;
data = create(10);
add_last(data, 20);
add_last(data, 30);
printf("%d, %d, %d\n", data
->val
, data
->next
->val
, data
->next
->next
->val
); printf("0x%X\n", data
->next
->next
); printf("0x%X\n", data
->next
->next
->next
); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKc3RydWN0IFhYWCB7CiAgICBzdHJ1Y3QgWFhYKiBuZXh0OwogICAgaW50IHZhbDsKfTsKCnN0cnVjdCBYWFgqIGNyZWF0ZShpbnQgdmFsKQp7CiAgICBzdHJ1Y3QgWFhYKiBkYXRhOwogICAgZGF0YSA9IChzdHJ1Y3QgWFhYKikgbWFsbG9jKHNpemVvZiAoc3RydWN0IFhYWCkpOwogICAgZGF0YS0+bmV4dCA9IE5VTEw7CiAgICBkYXRhLT52YWwgPSB2YWw7CiAgICByZXR1cm4gZGF0YTsKfQoKdm9pZCBhZGRfbGFzdChzdHJ1Y3QgWFhYKiBkYXRhLCBpbnQgdmFsKQp7CiAgICB3aGlsZSAoZGF0YS0+bmV4dCAhPSBOVUxMKSB7CiAgICAgICAgZGF0YSA9IGRhdGEtPm5leHQ7CiAgICB9CiAgICBkYXRhLT5uZXh0ID0gY3JlYXRlKHZhbCk7Cn0KCmludCBtYWluKHZvaWQpCnsKICAgIHN0cnVjdCBYWFgqIGRhdGE7CgogICAgZGF0YSA9IGNyZWF0ZSgxMCk7CiAgICBhZGRfbGFzdChkYXRhLCAyMCk7CiAgICBhZGRfbGFzdChkYXRhLCAzMCk7CiAgICBwcmludGYoIiVkLCAlZCwgJW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