Declaring Structure Variable : Some Important Things to Remember
Important Notes for Declaring Structure Variable
- Closing brace of structure type declaration must be followed by semicolon.
- Don’t forgot to use ‘struct‘ keyword
- Memory will not be allocated just by Creating instance or by declaring structure
- Generally Structures are written in Global Declaration Section , But they can be written inside main.
- It is not necessary to initialize all members of structure.
- For Larger program , Structures may be embedded in separate header file.
struct date { int date; char month[20]; int year; };
struct date
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;
int main() { struct student_database { char name[10]; int roll; int marks; }stud1; return(0); }
struct student_database { char name[10]; int roll; int marks; }stud1 = {"Pritesh"};