Pointers in C | HackerRank - Samsus Salehin Sabbir

Header Ads

Pointers in C | HackerRank


Problem Link : Pointers in C

Solution :
      Develop by
 Samsus Salehin Sabbir 




  1. #include <stdio.h>

  2. void update(int *a,int *b) {
  3.     // Complete this function
  4.     int temp = *a;
  5.     *a = (*(a))+(*(b));
  6.     *b = abs(temp-(*(b)));
  7.     //return temp,temp2; //no need to return beacouse auto return same address 
  8. }

  9. int main() {
  10.     int a, b;
  11.     int *pa = &a, *pb = &b; // create pointer and store address
  12.     
  13.     scanf("%d %d", &a, &b);
  14.     update(pa, pb); // passing address 
  15.     printf("%d\n%d\n", a, b); // 

  16.     return 0;
  17. }

No comments

Powered by Blogger.