Thursday, 20 March 2014

Cube a variable using call-by-reference with a pointer argument

/*….Hey guy’s this is the program reffered to the post i have posted i.e “CALL BY REFERENCE…”
/*…HOPE YOU LIKE IT….*/
#include <stdio.h>
void cubeByReference( int * );                                              /* prototype */
/*…Main Function Starts…*/
void main()
{
int number = 5;                                                                 /* Initialising….*/
printf( “The original value of number is %d”, number );
/*….Calling of Function…with arguments in it..*/
cubeByReference( &number );
printf( “\nThe new value of number is %d\n”, number );
getch();
}
/*…Main Function Ends..*/
/*…Function Definition Starts..*/
void cubeByReference( int *nPtr )
{
*nPtr = *nPtr * *nPtr * *nPtr; /* cube number in main */
}
/*….Function Definition Ends..*/

Image

No comments:

Post a Comment