Structure ये एक अलग-अलग data types का collection होता है |

अगर structure का इस्तेमाल करना हो तो 'struct' keyword का इस्तेमाल करते है |

Structure ये array के जैसा ही होता है |

Array similar data types का collection होता है और Structure different data type का collection होता है |

Structure में किये हुए हर variable के decaration को 'member' कहते है |

Structure हर एक member के लिए अलग-अलग memory allocate करता है |

Syntax for Structure Definition

struct structure_name{  

    data_type member 1;  
    data_type member 2;  
    data_type memeber n;  
};  

Example for Structure Definition

struct Employee{
    int emp_id;
    char emp_name[20];
    float salary;
};

यहाँ पर example में structure का नाम 'Employee' लिया है और structure के तीन Members है जिनके अलग-अलग तीन data types है | एक 'emp_id' के लिए integer है, एक 'emp_name' के लिए character है, एक float है जो 'salary' के लिए है |

Structure Variable Declaration

Structure का variable declare करने के दो प्रकार है |
  1. जब Structure की definition लिखी जाती तब वहा पर भी Structure variable को लिखा जाता है |
  2. Structure के variable को main() function के अंदर भी किया जाता है |


How to access Structure Members or Elements

Structure के Members को दो प्रकार से access किया जाता है |

  1. . (dot Operator)
  2. -> (pointer Operator)

1. Using .dot Operator
structure_variable_name . member_of_structure = value(optional); 
info.emp_id = 10;