Pointers in C

Sort by

recency

|

705 Discussions

|

  • + 0 comments

    This one can also be the simple one

    include

    void update(int *a,int *b) { int temp; temp = *a; *a = *a + *b; if(temp>*b) { *b = temp - *b; } else { *b = *b - temp; } // return *a; // return *b; // Complete this function
    }

    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
    #include <stdio.h>
    
    void update(int *a,int *b) {
        int max, diff;
        max = *a + *b;
        diff = abs(*a - *b);
        printf("%d\n%d",max,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

    Pointer in C.

    Here is an Easy Solution of the problem :

    #include <stdio.h>
    #include <stdlib.h>
    
    int update(int *a, int *b) {
        int temp_a = *a, temp_b = *b;
    
        *a = temp_a + temp_b;
        *b = abs(temp_a - temp_b);
    }
    
    int main() {
    
        int frst, scnd;
        int *p_frst = &frst, *p_scnd = &scnd;
    
        scanf("%d %d", &frst, &scnd);
    
        update(p_frst, p_scnd);
    
        printf("%d\n%d\n", frst, scnd);
    
        return 0;
    }
    
  • + 0 comments
    #include <stdio.h>
    #include <math.h>
    void update(int *a,int *b) 
    {
          int t1=*a, t2=*b;
          *a = t1+t2;
          *b = abs(t1-t2);
    }
    
    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
    #include <stdio.h>
    #include <stdlib.h>
    
    void update(int *a,int *b) {
        int temp = *a;
        *a = *a + *b;
        *b = abs(temp - *b);
    }
    
    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;
    }