Pass Arguments by Reference to a Function to set the values of the credit count of members. - C Function

C examples for Function:Function Parameter

Description

Pass Arguments by Reference to a Function to set the values of the credit count of members.

Demo Code

#include <stdio.h>

void changeCreditCount(int *p1, int *p2);

int main()//  w w  w .ja  v a  2  s  .  com
{
     int intCC1 = 15, intCC2 = 20;
    
     printf("Computer-control is in main() function\n");
    
     printf("intCC1 = %d and intCC2 = %d\n", intCC1, intCC2);
    
     changeCreditCount(&intCC1, &intCC2);
    
     printf("Computer-control is back in main() function\n");
    
     printf("intCC1 = %d and intCC2 = %d\n", intCC1, intCC2);
    
     return(0);
}

void changeCreditCount(int *p1, int *p2)
{
      printf("Computer-control is in changeCreditCount() function\n");
    
      printf("Initial values of *p1 and *p2: \n");
    
      printf("*p1 = %d and *p2 = %d\n", *p1, *p2);
    
      *p1 = *p1 * 4;
    
      *p2 = *p2 * 4;
    
      printf("Now values of *p1 and *p2 are changed\n");
    
      printf("*p1 = %d and *p2 = %d\n", *p1, *p2);
    
      return;
}

Related Tutorials