データ構造とc言語
1197 ワード
1.pointer
int y = 1; //variable y will live in the globals section, address is 1,000,000. And values is 1.
int main() {
int x = 4; //variable x will live in the stack section, address is 4,100,000. And values is 4.
return 0;
}
printf("x is stored at %p
", &x); // 「0x3E8FA0」print the address of variable x. This is 4,100,000 in hex (base 16) format.
int *address_of_x = &x;
printf("x is stored at %p
", address_of_x); // 0x7ffeeddd0ab8
printf("x is at %d
", *address_of_x); // 4
*address_of_x = 99; // reset value
2.struct:// 1.
struct fish{
const char *name;
int age;
};
struct fish snappy = {"Snappy", 78};
// 2. 「 typedef」
typedef struct fish{
const char *name;
int age;
};
struct fish snappy = {"Snappy", 78};
// 3. 「 : struct FI, :FI == struct fish」
typedef struct fish{
const char *name;
int age;
}FI;
FI snappy = {"Snappy", 78};
// :
void catalog(struct fish sh){
printf("%s . His age is %i
",sh.name , sh.age );
}
int main() {
printf("%d
", snappy.age);
catalog(snappy);
return 0;
}