Passing Structures by Reference - C Structure

C examples for Structure:Structure Value

Description

Passing Structures by Reference

Demo Code

#include <stdio.h> 
#include <string.h> 
typedef struct employee { 
  int id; /*from w  w w  .  ja  v  a 2  s.  c o m*/
  char name[10]; 
  float salary; 
} emp; 
void processEmp(emp *); 
int main()
{ 
   emp emp1 = {0, 0, 0}; 
   emp *ptrEmp; 
   ptrEmp = &emp1; 
   processEmp(ptrEmp); 
   printf("\nID: %d\n", ptrEmp->id); 
   printf("Name: %s\n", ptrEmp->name); 
   printf("Salary: $%.2f\n", ptrEmp->salary); 
}

void processEmp(emp *e) { 
   e->id = 123; 
   strcpy(e->name, "Mary"); 
   e->salary = 65000.00; 
}

Related Tutorials