Professional Documents
Culture Documents
PROGRAM:
#include<stdio.h>
int main()
int a;
int *pt;
a=10;
pt=&a;
clrscr();
printf("\n[a]:Value of A=%d",a);
printf("\n[*pt]:Value of A=%d",*pt);
printf("\n[&a]:Address of A=%p",&a);
printf("\n[pt]:Address of A=%p",pt);
printf("\n[&pt]:Address of pt=%p",&pt);
printf("\n[pt]:Value of pt=%p",pt);
return 0;
}
9.2.Write a c program to swap the two values by using pointers.
PROGRAM:
#include<stdio.h>
int temp;
temp=*value1;
*value1=*value2;
*value2=temp;
int main()
int number1,number2;
clrscr();
scanf("%d",&number1);
scanf("%d",&number2);
swap_numbers(&number1,&number2);
return 0;
}
9.3.Write a c program to print the address of character & the character of string using
pointer.
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
int *p,*pstr1;
char *str;
char c;
clrscr();
scanf("%c",&c);
scanf("%s",str);
p=&c;
pstr1=&str;
printf("\nValue of character=%c",c);
printf("\nValue of string=%s",str);
printf("\nAddress of character=%u",p);
printf();
getch();
}
9.4.Write a c program to access elements using pointers.
PROGRAM:
#include<stdio.h>
int main()
int data[5];
clrscr();
for(int i=0;i<5;++i)
scanf("%d",data + i)
for(int i=0;i<5;++i)
printf("%d\n",*(data+i));
return 0;
}
9.5.Write a program for sorting using pointers.
PROGRAM:
#include<stdio.h>
#include<stdio.h>
#include<alloc.h>
void main()
int n,*p,i,j,temp;
clrscr();
scanf("%d",&n);
p=(int *)malloc(n*2);
if(p==NULL)
exit();
for(i=0;i<n;i++)
scanf("%d",p+i);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(*(p+i)<*(p+j))
{
temp=*(p+i);
*(p+i)=*(p+j);
*(p+j)=temp;
for(i=0;i<n;i++)
printf("%d",*(p+i));
getch();