Write C Program to add two numbers using pointers


Introduction

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Write C Program to add two numbers using pointers


  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int num1, num2, sum;
  6. int *ptr1, *ptr2;
  7.  
  8. ptr1 = &num1; // ptr1 stores the address of num1
  9. ptr2 = &num2; // ptr2 stores the address of num2
  10.  
  11. //Inputting 2 numbers from user
  12. printf("Enter any two numbers: ");
  13. scanf("%d%d", ptr1, ptr2);
  14.  
  15. sum = *ptr1 + *ptr2;
  16.  
  17. printf("Sum of 2 numbers: %d", sum);
  18.  
  19. return 0;
  20. }
  21.  

Result

C language techstudy.org

     





Related Topics




Popular Posts