passing pointer in function

1 reply [Last post]
preeti
Offline
Last seen: 10 years 14 weeks ago
Joined: 2009-03-30
bOt Points: 85

can u plz tell me that how a pointer is passed in a function....

n/a
bOtskOOl
Offline
Last seen: 9 years 31 weeks ago
Joined: 2009-02-21
bOt Points: 3500
Example of passing pointer in a function

 

#include <conio.h>
#include <stdio.h>
 
void square(int *pointer); /* prototype */
 
void main()
{
  
   int *ptr;
   int x=10;
   clrscr();
   ptr=&x;
   square(ptr);
   square(&x); /*You can also pass values like this*/
   getch();
 
}
 
void square(int *pointer)
{
    *pointer = (*pointer)*(*pointer);
    printf("The value is %d\n", *pointer); /*Prints square of the number*/
 
 
}

Output will be like this:-

Passing pointer in a function