首页试题详情
难度: 使用次数:138更新时间:2026/03/13
1.
定义一个结构体指针时,下列哪项是正确的?
A.struct Student *p = (Student *)malloc(sizeof(Student));
B.Student *p = malloc(sizeof(Student));
C.struct Student *p = (struct Student *)malloc(sizeof(Student));
D.struct Student *p = malloc(Student);
题型:选择题 知识点:第二章 程序设计语言基础
【答案】
C
【解析】
在C语言中,malloc返回的是void指针,使用前需要强制转换。正确的做法是使用struct Student *p = (struct Student *)malloc(sizeof(Student));。选项A和B中的转换不正确,选项D语法错误。因此C选项正确。

查看答案和解析

支付 ¥0.1 即可查看此题答案和详细解析

低至 ¥0.1 起

类题推荐:

未分类