-->
Showing posts with label program to get difference of two numbers using pointer. Show all posts
Showing posts with label program to get difference of two numbers using pointer. Show all posts

program to get difference of two numbers using pointer

using codeblocks
-------------------------------------------------------------------------------------------------------------

//difference of two numbers using pointer     //comment of program
#include <stdio.h>                     //header file
int main()
{
    int *p,*p1;                      //two pointer declaration
    int x,y;                           //variable declaration
    printf("enter two values for x and y\n");//prints message
    scanf("%d%d",&x,&y);                    // gets input
    p=&x,p1=&y;                        //assigning address to that pointer
    printf("the address of x(%d) is=%d\n",x,p);//display of that address
    printf("the address of y(%d) is=%d\n",y,p1);//display of address of second variable
    printf("the difference=%d\n",*p-*p1);   
//display of difference stored in that address. we display that using indirection operator
    return 0;
}

-----------------------------------------------------------------------------------
using turbo c++
-----------------------------------------------------------------------------------------------------
//difference of two numbers using pointer     //comment of program
#include <stdio.h>                     //header file
#include<conio.h>                    //header file
int main()
{
    int *p,*p1;                      //two pointer declaration
    int x,y;                           //variable declaration
    printf("enter two values for x and y\n");//prints message
    scanf("%d%d",&x,&y);                    // gets input
    p=&x,p1=&y;                        //assigning address to that pointer
    printf("the address of x(%d) is=%d\n",x,p);//display of that address
    printf("the address of y(%d) is=%d\n",y,p1);//display of address of second variable
    printf("the difference=%d\n",*p-*p1);   
//display of difference stored in that address. we display that using indirection operator
   getch();                              //holds the output
    return 0;
}