Home >Backend Development >C++ >In C language, explain the concept of pointer structure with appropriate examples
The pointer to the structure saves the address of the entire structure.
Mainly used to create complex data structures, such as linked lists, trees, graphs, etc.
You can use a special operator (arrow operator -> ) to access the members of the structure.
The following is the declaration of a pointer to a structure:
struct tagname *ptr;
For example, struct Student *s;
You can access a pointer to a structure using the following code -
Ptr-> membername;
For example, s->sno, s->sname, s->marks;
The following is C program for pointer structure -
#include<stdio.h> 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</p><p>", st ->sno); printf ("name = %s</p><p>", st->sname); printf ("marks =%f</p><p>", st ->marks); getch ( ); }
When the above program is executed, the following results are produced-
enter sno, sname, marks:1 priya 34 details of the student areNumber = 1 name = priya marks =34.000000
The above is the detailed content of In C language, explain the concept of pointer structure with appropriate examples. For more information, please follow other related articles on the PHP Chinese website!