summaryrefslogtreecommitdiff
path: root/2/3_int_arith/227.c
blob: cc22cf948846b18d865af0d5167c69fab1018d6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
#include <limits.h>

// with limits.h
int uadd_ok(unsigned x, unsigned y) {
    printf("x: %u, y: %u\n", x, y);
    return x <= (UINT_MAX - y);
}

// without limits.h
int uadd_ok_without(unsigned x, unsigned y) {
    unsigned sum = x + y;
    return sum >= x;
}

void main() {
    printf("%u\n", UINT_MAX);
    printf("%d\n", uadd_ok(10, 20));
    printf("%d", uadd_ok(UINT_MAX / 2, UINT_MAX / 2));
}