Passing a Structure as an Argument - C Structure

C examples for Structure:Structure Value

Description

Passing a Structure as an Argument

Demo Code

#include <stdio.h>
#define FUNDLEN 50/*  w w w .jav  a2  s  .  c  o m*/

struct BackCount {
    char   bank[FUNDLEN];
    double bankfund;
    char   save[FUNDLEN];
    double savefund;
};

double sum(struct BackCount moolah);  /* argument is a structure */

int main(void){
    struct BackCount stan =  {"t1",1234.56,"t2",4321.21};
    
    printf("Stan has a total of $%.2f.\n", sum(stan));
    
    return 0;
}

double sum(struct BackCount moolah)
{
    return(moolah.bankfund + moolah.savefund);
}

Result


Related Tutorials