C Language Video

Back - C Language Notes By Vivek Sir email: vivekdubey22@gmail.com (w) 9826424484

Passing Structure Members as arguments to Function

·        Individual members of structure can pass to a function just like ordinary variables and also as composite.

 

The following program demonstrates how to pass structure members as arguments to the function.

 

#include<stdio.h>

 

/*

structure is defined above all functions so it is global.

*/

 

struct student

{

    char name[20];

    int roll_no;

    int marks;

};

 

void print_struct1(char name[], int roll_no, int marks);

void print_struct2(struct student temp);

 

int main()

{

    struct student stu = {"Tim", 1, 78};

    print_struct1(stu.name, stu.roll_no, stu.marks);

    print_struct2(stu);

    return 0;

}

 

void print_struct1(char name[], int roll_no, int marks)

{

    printf("Name: %s\n", name);

    printf("Roll no: %d\n", roll_no);

    printf("Marks: %d\n", marks);

    printf("\n");

}

 

void print_struct2(struct student temp)

{

    printf("Name: %s\n", temp.name);

    printf("Roll no: %d\n", temp.roll_no);

    printf("Marks: %d\n", temp.marks);

    printf("\n");

}


 

C Language Video

Back - C Language Notes By Vivek Sir email: vivekdubey22@gmail.com (w) 9826424484