08-02-2016, 04:10 PM
tripple pointer
===============
void main()
{
int x = 10;
int *p1,*p2,*p3;
p1 = &x; p2 = &p1; p3 = &p2;
printf("%d",*p3);
}
O/P
---
10
*p3 = *(*(*(p2)))
*
void main()
{
int x,y,z,*p1,*q1,*r1;
p1 = &x; q1 = &y; r1 = & z;
scanf("%d%d",p1,q1); // or *p1 = 10; * q1 = 20
*r1 = *p1 + *q1;
printf("sum = %d",*r1);
}
void main()
{
int x,y,z,*p1,*q1,*r1;
p1 = &x; q1 = &y; r1 = & z;
scanf("%d%d",p1,q1); // or *p1 = 10; * q1 = 20
if(*p1 > *q1)
*r1 = *p1;
else
*r1 = *q1;
printf("Big value = %d",*r1);
}
single pointer value - single pointer only
single pointer varaible address - double pointer only
double pointer value - double pointer only
double pointer varaible address - triple pointer only
pointer Airthemetic
=====================
int x = 10;
int *p;
p = &x;
p++;
printf("%d%d%d%d%d",x,*p,&x,p,&p);
p--;
printf("%d%d%d%d%d",x,*p,&x,p,&p);
(*p)++;
printf("%d%d%d%d%d",x,*p,&x,p,&p);
if p1 & p2 are two single pointers
*p1 + *p2, *p1 * *p2, *p1 / *p2 *p1 > *p2 are allowed
p1++, p1 + 2; allowed
p1 + p2 not allowed
p1 / p2
if you increment double, triple pointer values, it increases based on type of pointer only.
if you increment single pointer values, it increases based on the
data types to which it is pointng.
call by value? call by reference
--------------- ------------------
--------------------------------------------------------
1) the control will pass 1) the control will pass the address
only image of the values of variables to the called
to called function memebers. functions members
2) so, the changes made to the 2) Here, the changes made in the
called function members will called function members will
not reflect in the calling refelect to the calling
function members. function members.
void main()
{
int x = 10, y =20;
printf("x = %d, y = %d",x,y);
call(x,y);
printf("x = %d, y = %d",x,y);
}
call( int p,int q) )
{
p = p + q;
q = p - q;
p = p - q;
}
void main()
{
int x = 10, y =20;
printf("x = %d, y = %d",x,y);
call(&x,&y);
printf("x = %d, y = %d",x,y);
}
call( int *p,int *q) )
{
*p = *p + *q;
*q = *p - *q;
*p = *p - *q;
}
1D Numeric Arrays with pointer
==============================
void main()
{
int a[5] = {10,20,30,40,50},i;
int *p;
p = a;
// type - I
i=0;
while(i < 5)
{
printf("%d\n",*(p+i));
i = i + 1;
}
// type - II
i=0;
while(i < 5)
{
printf("%d\n",*p);
p++;
i = i + 1;
}
}
1D Numeric Arrays with pointer and function
===========================================
void main()
{
int a[5] = {10,20,30,40,50};
call(a);
}
call(int *p)
{
int i = 0;
// type - I
i=0;
while(i < 5)
{
printf("%d\n",*(p+i));
i = i + 1;
}
// type - II
i=0;
while(i < 5)
{
printf("%d\n",*p);
p++;
i = i + 1;
}
}
2d - numeric array with pointer
===============================
void main()
{
int a[2][2] = {10,20,30,40};
int *p1[2], *p2;
i = 0;
while(i<2)
{
p1[i] = &a[i];
i = i + 1;
}
p2 = p1;
// type - I
i = 0;
while(i<2)
{
j = 0;
while(j < 2)
{
printf("%d\t",*(*(p2+i)+j));
j = j + 1;
}
pritnf("\n"); i = i + 1;
}
// type - II
i = 0;
while(i<2)
{
j = 0;
while(j < 2)
{
printf("%d\t",*p2);
(*p2)++;
j = j + 1;
}
p2++;
pritnf("\n"); i = i + 1;
}
}
2d - numeric array with pointer and functions
=============================================
void main()
{
int a[2][2] = {10,20,30,40};
int *p1[2],i;
i = 0;
while(i<2)
{
p1[i] = a[i];
i = i + 1;
}
call (p1);
}
call(int *p2)
{
int i,j;
// type - I
i = 0;
while(i<2)
{
j = 0;
while(j < 2)
{
printf("%d\t",*(*(p2+i)+j));
j = j + 1;
}
pritnf("\n"); i = i + 1;
}
// type - II
i = 0;
while(i<2)
{
j = 0;
while(j < 2)
{
printf("%d\t",*p2);
(*p2)++;
j = j + 1;
}
p2++;
pritnf("\n"); i = i + 1;
}
}
//