Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
GreenGeeks Web Hosting - Faster, Scalable & Eco-Friendly

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


7,788 questions

10,874 answers

573 users

How to return struct containing values from a function in C

1 Answer

0 votes
#include <stdio.h>

typedef struct {
    int    age;      
    float    salary;     
}  Worker;

Worker function(int n)
{
    Worker w = {n, 8999};

    if (n > 70) 
        w.salary = w.salary + 1000;

    return w;
}

int main(void)
{
    Worker wo;
    
    wo = function(72);

    printf("age = %d  salary = %.2f\n", wo.age, wo.salary); 

    return 0;
}
    
/*
run:
 
age = 72  salary = 9999.00

   
*/

 




answered Aug 17, 2017 by avibootz
...