Pointer to Structure in C Programming

  1. Address of Pointer variable can be obtained using '&' operator.
  2. Address of such Structure can be assigned to the Pointer variable .
  3. Pointer Variable which stores the address of Structure must be declared as Pointer to Structure .
Syntax :
struct student_database
{
    char name[10]
    int roll;
    int marks;
}stud1; 
struct student_database *ptr;
ptr = &stud1;
How to Access Structure Members : 
Way 1 : Using Structure Name
Accessing Roll Number : stud1.roll
Accessing Name        : stud1.name
Way 2 : Using Indirection Operator and Pointer
Accessing Roll Number : (*ptr).roll
Accessing Name        : (*ptr).name
Way 3 : Using Membership Operator
Accessing Roll Number : ptr->roll;
Accessing Name        : ptr->name;


Bookmark & Share


Tags / Keywords : | , ,

0 comments

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email