面试题答案
一键面试#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
// 动态分配一个Student结构体的内存
struct Student *student = (struct Student *)malloc(sizeof(struct Student));
if (student == NULL) {
printf("内存分配失败\n");
return 1;
}
// 初始化id和name
student->id = 100;
strcpy(student->name, "Tom");
// 打印信息
printf("id: %d, name: %s\n", student->id, student->name);
// 释放内存
free(student);
student = NULL;
return 0;
}