#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct SSS {
char dummy[256];
int num;
};
void print_data1(struct SSS *d, char *name)
{
printf("%s = { [0]%d, [1]%d }\n", name
, d
[0].
num, d
[1].
num); }
void print_data2(struct SSS **d, char *name)
{
printf("%s = { [0]%d, [1]%d }\n", name
, d
[0]->num
, d
[1]->num
); }
int main()
{
struct SSS s1[2];
struct SSS *s2;
struct SSS **s3;
// s1
s1[0].num = 10;
s1[1].num = 11;
print_data1(s1, "s1");
// s2
s2
= (struct SSS
*) malloc(sizeof(struct SSS
) * 2); memset(s2
, 0xFF, sizeof(struct SSS
) * 2); s2[0].num = 20;
s2[1].num = 21;
print_data1(s2, "s2");
// s3
s3
= (struct SSS
**) malloc(sizeof(struct SSS
*) * 2); s3
[0] = (struct SSS
*) malloc(sizeof(struct SSS
)); s3
[1] = (struct SSS
*) malloc(sizeof(struct SSS
)); s3[0]->num = 30;
s3[1]->num = 31;
print_data1( s3, "s3(×)");
print_data1(*s3, "s3(×)");
print_data2( s3, "s3(○)");
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RkbGliLmg+CiNpbmNsdWRlPHN0cmluZy5oPgoKc3RydWN0IFNTUyB7CiAgICBjaGFyIGR1bW15WzI1Nl07CiAgICBpbnQgbnVtOwp9OwoKdm9pZCBwcmludF9kYXRhMShzdHJ1Y3QgU1NTICpkLCBjaGFyICpuYW1lKQp7CiAgICBwcmludGYoIiVzID0geyBbMF0lZCwgWzFdJWQgfVxuIiwgbmFtZSwgZFswXS5udW0sIGRbMV0ubnVtKTsKfQoKdm9pZCBwcmludF9kYXRhMihzdHJ1Y3QgU1NTICoqZCwgY2hhciAqbmFtZSkKewogICAgcHJpbnRmKCIlcyA9IHsgWzBdJWQsIFsxXSVkIH1cbiIsIG5hbWUsIGRbMF0tPm51bSwgZFsxXS0+bnVtKTsKfQoKaW50IG1haW4oKQp7CiAgICBzdHJ1Y3QgU1NTIHMxWzJdOwogICAgc3RydW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