Functions : Example for Passing structure to a function as an argument by reference method - 2

Functions : Example for Passing structure to a function as an argument by reference method

2. Pass Structure By Reference :


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

struct student
{
        int rno;
        char name [ 20 ];
        float per;
};

void Display( struct student *p );

main ( )
{
        struct student r;

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

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

void Display( struct student *p )
{
        printf ( " Rno is: %d \n ", p->rno );
        printf (" Name is: %s \n", p->name );
        printf (" Percentage is: %f \n", p->per );
}

Comments