* pointer
A pointer is a variable which is used to store address of another variable.
The syntax of pointer variable declaration is as follows:
datatype *pointer variable name
eg: let
int a=10; //&a=99;
int *p=&a;
*p=99;
|> change the value at the address of P.
* if we want to modify 'a' value from 10 to 99. we have to write a=99 to do this.
But we can also modify 'a' variable without accessing it directly. This can be done with the help of the pointer variable p.
The statement *p=99 means change the value at the address of p to 99.
By this way 'a' value becomes 99 without modifying directly, with the help of pointer variable.
/* C Program to swap 2 value using call by value and call by address */ By Amit raj purohit
http://codevidyalay.blogspot.com
#include<stdio.h>
void swapvalue(int,int);
void swapaddress(int*,int*);
int main()
{
int a=100,b=30;
printf("a and b values before swapping %d %d",a,b);
swapvalue(a,b);
printf("\na and b values after call by value %d %d",a,b);
swapaddress(&a,&b);
printf("\na and b values after call by address %d %d",a,b);
return 0;
}
void swapvalue(int a,int b)
{
int c;
c=a;
a=b;
b=c;
}
void swapaddress(int *p,int *q)
{
int c;
c=*p;
*p=*q;
*q=c;
}
INPUT/OUTPUT:
a and b values before swapping 100 30
a and b values after call by value 100 30
a and b values after call by address 30 100