Showing posts with label C++. Show all posts
Showing posts with label C++. Show all posts

26 April 2020

Bugforces (ft Education Codeforces Round 86)

Consider the following implementation to find the smallest multiple of x at least as big as y:

typedef long long i64;

i64
next_mult_ge(const i64 y, const i64 x)
{
    return ceil(y / (double) x) * x;
}

What can go wrong?

18 May 2017

A C puzzle

Consider the following C code:

#include <stdio.h>

enum bitmask
{
    bitmask_A = 1,
    bitmask_B = 2,
    bitmask_C = 4
};
typedef enum bitmask bitmask;

struct a_s
{
    bitmask member;
};
typedef struct a_s a_t;

bitmask
f(a_t *arg)
{
    arg->member |= bitmask_B;
    return bitmask_C;
}

int
main()
{
    a_t foo;
    foo.member = bitmask_A;
    foo.member |= f(&foo);
    printf("%d\n", foo.member);
    return 0;
}
What happens?