Pointers
Problem 1:-
#include<stdio.h>
#include<conio.h>
void main()
{
int *q, *p;
int a,b;
p=&a;
q=&b;
clrscr();
printf("\n\n\t\t Display the Address of variable using pointer");
printf("\n\t\t*****************************************
*****");
//prompt user to enter value
printf("\n\t Enter the value of a \t:\t");
scanf("%d",&a);
printf("\n\t Enter the value of b \t:\t");
scanf("%d",&b);
printf("\n\n\t Value of var a is \t:\t%d",a);
printf("\n\t Address of var a is \t:\t%u",&a);
printf("\n\n\t Value of var b is \t:\t%d",b);
printf("\n\t Address of var b is \t:\t%u",&b);
printf("\n\n\t Value of var a using pointer is \t:\t%d",*p);
printf("\n\t Address of var a using pointer is \t:\t%u",p);
printf("\n\n\t Value of var b using pointer is \t:\t%d",*q);
printf("\n\t Address of var b using pointer is \t:\t%u",q);
printf("\n\t Address of pointer p is \t:\t%u",&p);
printf("\n\t Address of pointer q is \t:\t%u",&q);
getch();
}
output 1:-
Problem 2:-
#include<stdio.h>
#include<conio.h>
void main()
{
int *p;
int *q;
int *r;
int a;
int b;
int c;
p=&a;
q=&b;
r=&c;
clrscr();
printf("\n\t\t Add the value of two variable and store in
another variable using pointer");
printf("\n\t\t*****************************************
********************************");
printf("\n\n\t Enter the first number \t:\t");
scanf("%d",&a);
printf("\n\t The value present in pointer p is \t:\t %d",*p);
printf("\n\n\t Enter the second number \t:\t");
scanf("%d",&b);
printf("\n\t The value present in pointer q is \t:\t %d",*q);
*r=*p + *q;
printf("\n\n\t The value present in var c is \t:\t %d",c);
getch();
}
output 2:
Display #include<stdio.h>
#include<conio.h>
void main()
{
//declaration and initilzation of variable
int a = 10;
int b =12;
int *x;
int *y;
int temp;
clrscr();
x=&a;
y=&b;
printf("\n\n\t\tswaping the value of two variable using
pointer");
printf("\n\t\t*****************************************
******");
printf("\n\t old value of a is : %d",a);
printf("\n\t old value of b is : %d",b);
//swaping the value
temp=*x;
*x=*y;
*y=temp;
printf("\n\n\t After swaping the value of a is : %d",a);
printf("\n\t After swaping the value of b is : %d",b);
getch();
}
Program output: