Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Saturday 27 January 2018

Addition of two numbers using pointers

This program performs addition of two numbers using pointers.

I have assign the addresses of x and y to p and q respectively and then assign the sum of x and y to variable sum. & is address of operator and * denotes value at that address.

Example

#include <stdio.h> int main() { int first, second, *p, *q, sum; printf("Enter two integers to add\n"); scanf("%d%d", &first, &second); p = &first; q = &second; sum = *p + *q; printf("Sum is = %d\n",sum); return 0; }


No comments:

Post a Comment