/*
* ポインタの活躍例
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct PERSON {
char name[32], address[256], phone[16], e_mail[16];
int age;
};
void print_data_struct(struct PERSON d)
{
printf("name = %s\n", d.
name); // …
}
void print_data_pointer(struct PERSON *d)
{
printf("name = %s\n", d
->name
); // …
}
int main()
{
struct PERSON data;
// data 作成
// …
printf("print_data_struct ( data); 実行… ");print_data_struct
( data
); printf("print_data_pointer(&data); 実行… ");print_data_pointer
(&data
); printf("\nポインタ使用の有無によって、関数に渡すデータのサイズは異なる\n"); printf(" ・ポインタ使用せず ~ sizeof(struct PERSON ) = %3d\n", sizeof(struct PERSON
)); printf(" ・ポインタ使用する ~ sizeof(struct PERSON *) = %3d\n", sizeof(struct PERSON
*));
return 0;
}
LyoKICogICAgICDjg53jgqTjg7Pjgr/jga7mtLvouo3kvosKICovCiNpbmNsdWRlPHN0ZGlvLmg+CiNpbmNsdWRlPHN0ZGxpYi5oPgojaW5jbHVkZTxzdHJpbmcuaD4KCnN0cnVjdCBQRVJTT04gewogICAgY2hhciBuYW1lWzMyXSwgYWRkcmVzc1syNTZdLCBwaG9uZVsxNl0sIGVfbWFpbFsxNl07CiAgICBpbnQgYWdlOwp9OwoKdm9pZCBwcmludF9kYXRhX3N0cnVjdChzdHJ1Y3QgUEVSU09OIGQpCnsKICAgIHByaW50ZigibmFtZSA9ICVzXG4iLCBkLm5hbWUpOwogICAgLy8g4oCmCn0KCnZvaWQgcHJpbnRfZGF0YV9wb2ludGVyKHN0cnVjdCBQRVJTT04gKmQpCnsKICAgIHByaW50ZigibmFtZSA9ICVzXG4iLCBkLT5uYW1lKTsKICAgIC8vIOKApgp9CgppbnQgbWFpbigpCnsKICAgIHN0cnVjdCBQRVJTT04gZGF0YTsKCiAgICAvLyBkYXRhIOS9nOaIkAogICAgc3RyY3B5KGRhdGEubmFtZSwgIuWQjeWJjSIpOwogICAgLy8g4oCmCgogICAgcHJpbnRmKCJwcmludF9kYXRhX3N0cnVjdCAo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