Use pointers to pass arguments by reference. - C Function

C examples for Function:Function Parameter

Description

Use pointers to pass arguments by reference.

Demo Code

#include <stdio.h> 

void demoPassByReference(int *); 
int main()/*  w ww  .j ava  2  s  .  c  o m*/
{ 
   int x = 0; 
   printf("\nEnter a number: "); 
   scanf("%d", &x); 
   demoPassByReference(&x); 
   printf("\nThe original value of x is: %d\n", x); 
} 
void demoPassByReference(int *ptrX) 
{ 
   *ptrX += 5; 
   printf("\nThe value of x is now: %d\n", *ptrX); 
} 

Related Tutorials