Structure with Pointers in C
Syntax to declare structure type pointer variable is:
struct Struct_name *var;
var represents pointer variable of structure.
We can use pointer variable of structure to access its elements pointer in two ways:
- (->) arrow operator
- (.) dot operator
Program to demonstrate use of pointer variable of a structure. |
#include<stdio.h> struct emp { int empid; float sal; }; int main() { struct emp e1={101,50000.00}; struct emp *e2; e2=&e1; printf(“\nEmpid=%d”,e2->empid); printf(“\nSalary=%f”,(*e2).sal);return(0); } |
Output |
Empid=101 Salary=50000.00 |
Popular Books of Computer Science