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

program to get sum of two numbers using pointer

using codeblocks
----------------------------------------------------------------------
//sum 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 sum=%d\n",*p+*p1); 
 //display of sum stored in that address. we display that using indirection operator
    return 0;
}
-----------------------------------------------------------------------------------------------
using turboc++
------------------------------------------------------------------------------------------
//sum of two numbers using pointer     //comment of program
#include <stdio.h>                     //header file
#include<conio.h>
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 sum=%d\n",*p+*p1);    
//display of sum stored in that address. we display that using indirection operator
    getch();
    return 0;
}