Structure initialization:
- Like Primitive types and Arrays, we can assign values directly to structure variables at the time of declaration.
- struct identity var = {val1, val2, val3 …};
- Accessor (dot operator): We must access the locations of structure through dot(.) operator
#include<stdio.h> struct Employee { int id; char name[20]; float salary; }; int main() { struct Employee e = {101, “amar”, 35000}; printf(“Employee id : %d \n”, e.id); printf(“Employee name : %s \n”, e.name); printf(“Employee salary : %f \n”, e.salary); return 0; } |
