Home > Backend Development > C++ > body text

In C language, explain the concept of pointer structure with appropriate examples

WBOY
Release: 2023-09-03 18:29:06
forward
1060 people have browsed it

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.

Declaration

The following is the declaration of a pointer to a structure:

struct tagname *ptr;
Copy after login

For example, struct Student *s;

Access

You can access a pointer to a structure using the following code -

Ptr-> membername;
Copy after login

For example, s->sno, s->sname, s->marks;

Example

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 ( );
}
Copy after login

Output

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
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!