Write a program to show different ways of passing structure to a function.
#include<stdio.h> typedef struct mobile { char brand[12]; int model; float price; }MOBILE; void print_structure_member_by_member(char*,int,float); void print_strcure_by_passing_structure(MOBILE); void print_strcure_by_passing_structure_pointer(MOBILE*); int main() { MOBILE v = {"BlackBerry",7,12999.99}; print_structure_member_by_member(v.brand,v.model,v.price); print_strcure_by_passing_structure(v); print_strcure_by_passing_structure_pointer(&v); return 0; } void print_structure_member_by_member(char* b,int m,float p) { printf("%s %d %f\n",b,m,p); } void print_strcure_by_passing_structure(MOBILE a) { printf("%s %d %f\n",a.brand,a.model,a.price); } void print_strcure_by_passing_structure_pointer(MOBILE *a) { printf("%s %d %f\n",a->brand,a->model,a->price); }
Output
BlackBerry 7 12999.990234 BlackBerry 7 12999.990234 BlackBerry 7 12999.990234