Search This Blog

Loading...

C example of passing Structure to Function.

//Code for Example of passing structure to function in C Programming

struct student
     {
    name char[30];
    marks float;
     }
main ( )
{
    struct student student1;
    student1 = read_student ( )
    print_student( student1);
    read_student_p(student1);
    print_student (student1);
 }


struct student read_student( )    \\ A
{
    struct student student2;
    gets(student2.name);
    scanf(“%d”,&student2.marks);
    return (student2);
}
 

  void print_student (struct student student2)    \\ B
{
printf( “name is %s\n”, student2.name);
printf( “marks are%d\n”, student2.marks);
}
 

  void read_student_p(struct student student2)    \\ C
{
    gets(student2.name);
    scanf(“%d”,&student2.marks);
}

1 comment:

  1. can you please let me know what is the advantage of declaring a function with struct datatype,
    ex: typedef struct football{
    int n;
    char*p;
    struct football*fb;
    }football;

    football*show(char*name)/*pls tell me the use of this func
    {//code goes here}

    /*rather than the above,what happens if i declare a func like this
    void show(football*name){
    }

    mail me on :diasmithunsmith@gmail.com

    ReplyDelete