> ~ Online tutorial


Pre-initializing Static Structures
In the chapter on arrays it was shown how static and external type arrays could be initialized with values at compile time. Static and external structures can also be pre-assigned by the compiler so that programs can set up options and starting conditions in a convenient way. A static variable of type PersonDat (as in the example programs) could be declared and initialized in the same statement:
#define NAMESIZE 20
#define ADDRESSSIZE 22

struct PersonDat
   {
   char *name;
   char *address;
   int YearOfBirth;
   int MonthOfBirth;
   int DayOfBirth;
   };

main ()

{ static struct PersonalData variable =
       {
       "Alice Wonderment",
       "Somewhere in Paradise",
       1965,
       5,
       12
       };

/* rest of program */

}

The items in the curly braces are matched to the members of the structure variable and any items which are not initialized by items in the list are filled out with zeros.

Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: BloggerYard.Com

0 comments: