Functions - Accessing structure in function directly when it is declared as global variable

Example 3 : Functions - Accessing structure in function directly when it is declared as global variable

 # include < stdio.h >
# include < string.h >

struct student
{
        int rno;
        char name [ 20 ];
        float per;
}r; /* structure variable r is declared as global */

void Display( );

main ( )
{
        r.rno=1;
        strcpy ( r.name, "DICEKPL" );
        r.per = 94.3;

        Display (  ); /* Passing structure variable r as argument to function Display() by value method */
           
}

void Display(  )
{
        printf ( " Rno is: %d \n ", r.rno );
        printf (" Name is: %s \n", r.name );
        printf (" Percentage is: %f \n", r.per );
}

Comments