290 Programming and Data Structures
Address of 'a / & 'b ' are stored in 'a p ' & %bp' respectively. Thus adding x*ap ' & '*b p ' gives
addition of 'a ' & 'b'.Here, 'a p ' & 'b p' means addresses of 'a ' & 'b' and ' *ap' & '*b p # means
the values at memory locations. Hence, the equation used here is d= * ap+*bp; & no t d=ap+bp.
9.9 Write a program to assign pointer value to another variable.
# include <stdio.h>
# include <conio.h>
malnQ
{
int a*5,b,*c;
c*&a;
b»*c;
clrsc rO ;
printf ( nMemory location of'a '= % u "c );
printf ("n The value ofa=%d&c b=%d",a,b);
I
Q i m i l L
Memory location of 'a'= 4062
The value of a=5 & b=5
Explanation In the above program, the pointer variable ' c ' is assigned in the memory location of
% a '. The value stored in this memory location is assigned to 'b ' through pointer *c.
9.10 Write a program to assign value of 'b ' to " through pointers. Show the effect of addition
before and after assignment of value of 'b ' to'a'.
# include <stdio.h>
# include <conio.h>
void main ()
{
in t a#b,*pa,*pb;
clrscr ();
printf ("Enter Value of'a'&c
scanf ("% d %d",&a,&b);
pa=6uz;
pb=&b;
printf ("nValue ofa=%d&a b=%d",a,b);
printf ( “
Address ofa=% u",pa);
printf ("nAddress ofb=% u ",pb);
printf ( “nnAddition of'a'&z 'b ': % d",*pa+*pb);
pa=pb;
printf ( ‘n *p a =% d *pb=%d",*pa,*pb);
printf ( “
pa =%u pb=%u",pa,pb);
printf ( “ nAddition of*pa + *p b : % d",*pa+*pb);
getcheO;
i