C语言学习(结构体指针,函数指针)

本文介绍了C语言中的结构体指针和函数指针。结构体指针用于引用结构体变量,而函数指针则用于表示函数的地址,常用于回调函数的传递。文中通过示例解释了函数指针的声明和使用,强调了函数指针在模拟类和对象系统中的应用。
摘要由CSDN通过智能技术生成

结构体指针

#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
struct Person
{
   
    char *name;
    int age;
    int height;
    int weight;
};
struct Person *Person_create(char *name, int age, int height, int weight)
{
   
    struct Person *who = malloc(sizeof(struct Person));
    assert(who != NULL);
    who->name = strdup(name);
    who->age = age;
    who->height = height;
    who->weight = weight;
    return who;
}
void Person_destroy(struct Person *who)
{
   
    assert(who != NULL);
    free(who->name);
    free(who);
}
void Person_print(struct Person *who)
{
   
    printf("Name: %s\n", who->name);
    printf("\tAge: %d\n", who->age);
    printf("\tHeight: %d\n", who->height);
    printf("\tWeight: %d\n", who->weight)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值