c语言程序设计指针进阶,C语言及程序设计进阶例程-15 指向结构体的指针
賀老師教學鏈接??C語言及程序設計進階?本課講解
指向結構體變量的指針的應用
#include
#include
struct Student
{
int num;
char name[12];
char sex;
float score;
};
int main( )
{
struct Student stu;
stu.num=10301;
strcpy(stu.name, "Wang Fun");
stu.sex='f';
stu.score=89.5;
struct Student *p=&stu;
printf("%d %s %c %.1f\n", stu.num, stu.name, stu.sex, stu.score);
printf("%d %s %c %.1f\n", (*p).num, (*p).name, (*p).sex, (*p).score);
printf("%d %s %c %.1f\n", p->num, p->name, p->sex, p->score);
return 0;
}
用指向結構體變量的指針作實參
#include
#include
struct Student
{
int num;
char name[12];
float score[3];
};
void print(struct Student*);
int main( )
{
struct Student stu,*pt;
stu.num=12345;
strcpy(stu.name, "Li Fung");
stu.score[0]=67.5;
stu.score[1]=89;
stu.score[2]=78.5;
pt=&stu;
print(pt);
printf("%d %s ", stu.num, stu.name);
printf("%.1f %.1f %.1f\n", stu.score[0], stu.score[1], stu.score[2]);
return 0;
}
void print(struct Student *p)
{
printf("%d %s ", p->num, p->name);
printf("%.1f %.1f %.1f\n", p->score[0], p->score[1], p->score[2]);
p->score[2]=100;
}
總結
以上是生活随笔為你收集整理的c语言程序设计指针进阶,C语言及程序设计进阶例程-15 指向结构体的指针的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 单机编程c语言,完美的8051单机C语言
- 下一篇: C语言sopc蜂鸣器按键弹奏中音,基于s