Declaring Structure Variable : Some Important Things to Remember



Important Notes for Declaring Structure Variable

  1. Closing brace of structure type declaration must be followed by semicolon.
  2. struct date
    {
         int date;
         char month[20];
         int year;
    };
    
  3. Don’t forgot to use ‘struct‘ keyword
  4. struct date
    
  5. Memory will not be allocated just by Creating instance or by declaring structure
  6. Memory will not be allocated just by writing following declaration -

    struct date
    {
         int date;
         char month[20];
         int year;
    };
    

    Memory will be allocated on defining it i.e -

    date d1;
    
  7. Generally Structures are written in Global Declaration Section , But they can be written inside main.
  8. int main()
    {
    struct student_database
    {
        char name[10];
        int roll;
        int marks;
    }stud1;
    return(0);
    }
    
  9. It is not necessary to initialize all members of structure.
  10. struct student_database
    {
        char name[10];
        int roll;
        int marks;
    }stud1 = {"Pritesh"};
    
  11. For Larger program , Structures may be embedded in separate header file.