Example of Structure Processing

#include <iostream.h>
/***********************************************
   File: struct1.C
   Assign values to members of a structured date
   then print them.
***********************************************/

struct date {
     int day;
     int month;
     int year;
};
typedef date Date;    

int main()
{
     Date today; //define Date variable today
     
     today.day = 31;
     today.month = 3;
     today.year = 1997;

     cout << "Today\'s date is " << today.day << ' '; 
     cout << today.month << ' ' << today.year << endl;
    
     exit(0);
}


#include <iostream.h> /********************************************************* File: struct2.C Assign values to members of a structured date then print them. The structured date value is manipulated through pointers *********************************************************/ struct date { int day; int month; int year; }; typedef date Date; /* variable and ...*/ typedef Date *Ptrdate; /* ...pointer types */ int main() { Date today; // Define Date variable today Ptrdate ptrdate; // Declare Date pointer ptrdate ptrdate = &today; // Point ptrdate to today ptrdate -> day = 31; ptrdate -> month = 3; ptrdate -> year = 1997; cout << "Today\'s date is " << ptrdate->day << ' '; cout << ptrdate->month << ' ' << ptrdate->year << endl; exit(0); }



Back to Previous Page

Document:
Local Date:
Last Modified On: