Passing Structures To Functions by Value - C Structure

C examples for Structure:Structure Value

Description

Passing Structures To Functions by Value

Demo Code

#include <stdio.h> 
#include <string.h> 
typedef struct employee { 
  int id; /*www .  j av a2  s. c o m*/
  char name[10]; 
  float salary; 
} e; 

void processEmp(e); //supply prototype with structure alias name 
int main()
{  
   e emp1 = {0,0,0}; //Initialize members 
   processEmp(emp1); //pass structure by value 
   printf("\nID: %d\n", emp1.id); 
   printf("Name: %s\n", emp1.name); 
   printf("Salary: $%.2f\n", emp1.salary); 
}
void processEmp(e emp) //receives a copy of the structure 
{ 
   emp.id = 123; 
   strcpy(emp.name, "Sheila"); 
   emp.salary = 65000.00; 
} //end processEmp

Related Tutorials