Pointers in C

Sort by

recency

|

675 Discussions

|

  • + 0 comments

    include

    include

    void update(int *a,int *b) {

    *a= (*a + *b);
    *b= abs(*a - *b- *b); 
    

    } int main() { int a, b;

    scanf("%d", &a);
    scanf("%d", &b);
    int *pa = &a, *pb = &b;
    update(pa, pb);
    printf("%d\n", a);
    printf("%d\n", b);
    
    return 0;
    

    }

  • + 0 comments

    This challenge offers a great opportunity to build foundational skills and apply them to practical scenarios! 11xplay.pro

  • + 0 comments
    #include <stdio.h>
    void update(int *a,int *b) {
        // Complete this function    
         int sum,diff;
         sum = *a+*b;
         diff = abs(*a-*b);
         *a = sum;
         *b = diff;
    }
    
    int main() {
        int a, b;
        int *pa = &a, *pb = &b;
        
        scanf("%d %d", &a, &b);
        update(pa, pb);
        printf("%d\n%d", a, b);
    
    
        return 0;
    }
    
  • + 0 comments

    Addition and subtraction using pointers

    I included <stdlib.h> to use abs() function. Here you can see my code snippet for your reference. If you have any idea feel free to comment.

    #include<stdio.h>
    #include<stdlib.h>
    
    void update(int *a,int *b) {
        //declaring temporary variable to store the values
        int c,d;
        c = *a +*b;  
        d = *b - *a;
    
        //assigning value to pointer variable
        *a = c;
        *b = d;
    }
    
    int main() {
        int a, b;
        int *pa = &a, *pb = &b;
        
        scanf("%d %d", &a, &b);
    
        //function calling
        update(pa, pb);
       
    //using abs() to return positive integer according to requirement
     printf("%d\n%d", a, abs(b));
    
        return 0;
    }
    
  • + 0 comments

    include

    include

    void update(int *a,int *b) { *a=*a + *b; *b=abs(*a - *b); // Complete this function
    }

    int main() { int a, b; int *pa = &a, *pb = &b;

    scanf("%d %d", &a, &b);
    update(&a, &b);
    printf("%d\n%d", a, b);
    
    return 0;
    

    }