Structure and Pointers
Learn how to create a pointer to a structure and an array of structures in C.
What is a structure pointer?
Example program
The program given below demonstrates the use of a structure pointer.
Press + to interact
# include <stdio.h>int main( ){// Declare structure bookstruct book{char n[ 20 ] ;int nop ;float pr ;} ;// Initialize structure variablestruct book b = { "Basic", 425, 135.00 } ;// Declare pointer to structure variablestruct book *ptr;// Store address of structure variableptr = &b;// Access structure elements using dot operatorprintf ( "%s %d %f\n", b.n, b.nop, b.pr ) ;// Access structure elements using arrow operatorprintf ( "%s %d %f\n", ptr->n, ptr->nop, ptr->pr ) ;}
Explanation
In the code given above, ptr
is a pointer to a structure, ...
Access this course and 1400+ top-rated courses and projects.