Pointers in C

Sort by

recency

|

700 Discussions

|

  • + 0 comments

    more easier

    #include <stdio.h>
    #include <stdlib.h>
    
    void update(int *a,int *b) {
            int plus, sub;
    
            plus = *a + *b;
            sub = *a - *b;
            *a = plus;
            *b= abs(sub);
    }
    
    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

    For C

    #include<stdio.h>
    #include<stdlib.h>
    
    void update(int *a, int *b)
    {
        int temp_a = *a;
        int temp_b = *b;
        
        *a = temp_a + temp_b;
        *b = abs(temp_a - 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;
    }
    
  • + 0 comments

    Using abs() from stdlib

    #include <stdio.h>
    #include <stdlib.h>
    
    void update(int *a,int *b) {
        // Complete this function
        int aTemp = *a;
        int bTemp = *b;
        *a = aTemp + bTemp;
        *b = abs(aTemp - bTemp);
    }
    
    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

    This explanation of pointers in C does a fantastic job of breaking down one of the most important — yet often confusing — concepts in programming. Funinexchange ID Login

  • + 0 comments

    t456