Passing a Structure to a Function
Learn how to pass a structure and its elements to a function.
Passing structure elements
We can pass elements of a structure either by value or by reference.
Passing structure elements by value
The basic syntax of passing elements of a structure by value is given below:
functionName (structVariable.memberName);
See the code given below!
Press + to interact
# include <stdio.h>void display ( char *, int, float ) ;int main( ){struct book{char n[ 20 ] ;int nop ;float pr ;} ;struct book b = { "Basic", 425, 135.00 } ;// Passing structure elements by valuedisplay ( b.n, b.nop, b.pr ) ;return 0 ;}// Pass by valuevoid display ( char *n, int pg, float p ){printf ( "%s %d %f\n", n, pg, p ) ;}
A pure call by value is not possible here, since we cannot pass the array, n
, by value. It ...
Access this course and 1400+ top-rated courses and projects.