MST

星途 面试题库

面试题:C语言指针访问结构体成员的基础应用

假设有如下结构体定义:struct student { int id; char name[20]; float score; }; 请使用指针访问结构体成员的方式,编写一个函数void printStudent(struct student *stu),用于打印结构体中各成员的值。
31.0万 热度难度
编程语言C

知识考点

AI 面试

面试题答案

一键面试
#include <stdio.h>

struct student {
    int id;
    char name[20];
    float score;
};

void printStudent(struct student *stu) {
    printf("ID: %d\n", stu->id);
    printf("Name: %s\n", stu->name);
    printf("Score: %.2f\n", stu->score);
}