Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

Different ways to declare a structure & its variable

Way 1C Programming Language Structure and Structure Variable Declaration 1Way 2C Programming Language Structure and Structure Variable Declaration 2Way 3C Programming Language Structure and Structure Variable Declaration 3Note

We can create any number of structure variables inside or outside the function.

Accessing Structure Member

Any member of a structure can be accessed using dot(.) operator, as shown below:

Syntax

structure_variable.structure_member;

Example

struct Employee
{
    int id_no;
    char name[30];
    float salary;
}    emp1,emp2;

 emp1.id_no; // accesses id_no of emp1
 emp1.name; // accesses name of emp1
 emp1.salary; // accesses salary of emp1
 emp2.id_no; // accesses id_no of emp2
 emp2.name; // accesses name of emp2
 emp2.salary; // accesses salary of emp3

 

Leave a reply