What will be printed as a result of code execution:
#include <iostream>
#include <stdint.h>

struct A {
    int value;
};

struct B {
    uint8_t value;

    B(A & a) {
        value = a.value;
    }
};

void func(B b) {
    std::cout << (int)b.value;
}

int main(int argc, char * argv[]) {
    A a = { 300 };
    func(a);
}
Explanation
The function call is allowed due to the presence of a class B constructor with the parameter type A.
The number 300 is converted to 44 because when converting int to uint8_t, 8 lower bits will be saved in B constructor, i.e. 300 & 0xff = 44.
You can read about stdint.h here: stdint.h.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
C++ quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes