
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Clarity on Pointer Structures with Example in C Language
Pointer to structure holds the address of an entire structure.
Mainly, these are used to create the complex data structures such as linked lists, trees, graphs and so on.
The members of the structure can be accessed by using a special operator called arrow operator ( -> ).
Declaration
Following is the declaration for pointer to structure −
struct tagname *ptr;
For example, struct student *s;
Accessing
You can access pointer to structure by using the following −
Ptr-> membername;
For example, s->sno, s->sname, s->marks;
Example
Following is the C program of the pointer structures −
#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
", st ->sno); printf ("name = %s
", st->sname); printf ("marks =%f
", st ->marks); getch ( ); }
Output
When the above program is executed, it produces the following result −
enter sno, sname, marks:1 priya 34 details of the student areNumber = 1 name = priya marks =34.000000
Advertisements