Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
c Passing Pointers to Functions

c Passing Pointers to Functions

Ratings: (0)|Views: 128|Likes:
Published by Rakesh Patel

More info:

Published by: Rakesh Patel on Aug 14, 2013
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

02/16/2014

pdf

text

original

 
http://www.tutorialspoint.com/cprogramming/c_passing_pointers_to_functions.htm
Copyright © tutorialspoint.com
PASSING POINTERS TO FUNCTIONS IN C
C programming language allows you to pass a pointer to a function. To do so, simply declare the function parameter asa pointer type.Following a simple example where we pass an unsigned long pointer to a function and change the value inside thefunction which reflects back in the calling function:
#include <stdio.h>#include <time.h> voidgetSeconds(unsigned long *par); intmain(){ unsigned longsec; getSeconds( &sec);  /* print the actual value */printf("Number of seconds: %ld\n",sec);  return 0; }voidgetSeconds(unsigned long *par) { /* get the current number of seconds */ *par=time(NULL);  return;}
When the above code is compiled and executed, it produces following result:
Number of seconds :1294450468
The function which can accept a pointer, can also accept an array as shown in the following example:
#include <stdio.h> /* function declaration */doublegetAverage(int *arr, intsize);  intmain(){ /* an int array with 5 elements */ intbalance[5] = {1000, 2, 3, 17, 50};  doubleavg;  /* pass pointer to the array as an argument */avg=getAverage(balance, 5 ) ;  /* output the returned value */printf("Average value is: %f\n",avg);  return 0; }doublegetAverage(int *arr, intsize) { inti,sum= 0;  doubleavg; 

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->