在C语言中,指针是指向结构体的指针
结构体指针保存了整个结构体的加法。
它用于创建复杂的数据结构,如链表、树、图等。
成员可以使用称为箭头运算符 ( -> ) 的特殊运算符来访问结构体。
声明
以下是 C 编程中指向结构体的指针的声明 -
struct tagname *ptr;登录后复制
访问
下面解释了如何访问结构体指针。
Ptr-> membername;登录后复制
示例程序
以下程序显示了结构体指针的用法 - p>
#include struct student{ int sno; char sname[30]; float marks; }; main ( ){ struct student s; struct student *st; printf("enter sno, sname, marks:"); scanf ("%d%s%f", & s.sno, s.sname, &s. marks); st = &s; printf ("details of the student are"); printf ("Number = %d
", st->sname); printf ("marks =%f
", st ->marks); getch ( ); }