06-データ構造_予備知識-クロス関数使用メモリ
895 ワード
C言語の部分を参照してください.
#include <stdio.h>
#include <malloc.h>
#include <string.h>
/*
1, A
2, A , B
:
1, createStudent ,
2, printStudent ,
*/
struct Student
{
int id;
char name[100];
int age;
};
// ,
struct Student * createStudent(void);
//
void printStudent(struct Student * pSt);
int main(void)
{
struct Student * pSt = NULL;
pSt = createStudent();
printStudent(pSt);
return 0;
}
struct Student * createStudent()
{
struct Student * pSt = (struct Student *) malloc( sizeof(struct Student) );
pSt->id = 123;
strcpy(pSt->name, " ");
pSt->age = 20;
return pSt;
}
void printStudent(struct Student * pSt)
{
printf("%d, %s, %d
", pSt->id, pSt->name, pSt->age);
return;
}