Professional Documents
Culture Documents
1000
2000 50
1000
A
• Address of A ?
1000
• Address of pointer ?
2000
How to declare a pointer?
use * preceding the variable name
int *x;
Datatype of a pointer
All pointers are typed based on the type of entity
that they point to
Pointer to integer data
int *x
Pointer to float type data
float *y
Pointer to Character type data
char *z
How to make a pointer to point?
int a; 1000 50 2000 1000
a
a=50; x
int *x;
How to make the pointer x to point the data a?
use & before the variable
x = &a ;
Output:
Value of a:100
Value of b:200
Call by Reference
original
• Only used with trusted functions
Call by reference
void main()
{
int a=100, b=200;
void swap(int *a, int *b)
{
swap(&a, &b); // passing address / reference
int temp;
to function
temp=*a;
printf("\nValue of a: %d",a);
*a=*b;
printf("\nValue of b: %d",b);
*b=temp;
}
}
Output:
Value of a:200
Value of b:100
Call by value Call by reference
Calling function sends copies to data Calling function sends address of data
Any changes in formal parameters does Any changes in formal parameters also
not affect the actual parameters affects the actual parameters