C - Write program to initialize structure array

Requirements

Write program to initialize structure array

Demo

#include <stdio.h>

int main()//from  www  .j  a  v a2 s.  co  m
{
    struct president
    {
        char name[40];
        int year;
    } preslist[] = {
        { "George Washington",1789 },
        { "John Adams", 1797 }
    };

    printf("The first president of the USA was %s\n",preslist[0].name);
    printf("He was inaugurated in the year %d\n",preslist[0].year);
    printf("The second president of the USA was %s\n",preslist[1].name);
    printf("He was inaugurated in the year %d\n",preslist[1].year);

    return(0);
}

Result

Related Exercise