Program: Program to illustrate a function that assigns value to the structure.
#include<stdio.h>
#include<stdlib.h>
//declare structure Date
struct Date
int yr;
int day;
int month;
}
//declare function to assign date to structure variable
void set_date(struct Date *dte, int dt, int mnt, int year)
dte->day = dt;
dte->yr = year;
dte->month = mnt;
}
int main(void)
date1.yr = 2004;
date1.day = 4;
//assigning values one by one
date1.month = 12;
//assigning values in a single statement
set_date(&date2, 05, 12, 2008);
//prints both dates in date/month/year format
printf("\n %d %d %d ", date1.day, date1.month, date1.yr);
printf("\n %d %d %d ", date2.day, date2.month, date2.yr);
return 0;
}
Output:
4 12 2004
5 12 2008
Explanation:
Two variables of type Date are created and named 'date1', 'date2'. 'date2' is assigned by using the function set_date(..). Address of 'date2' is passed to set_date function.