In case of the following type conversions, what is the output of the program?
#include <iostream>

int main() {
    float a = 256.5;
    unsigned char b = static_cast<unsigned char>(a);
    a += b + 1.f;
    
    std::cout << static_cast<int>(a);
}
Explanation
Floating-integral conversions
An rvalue of a floating-point type can be converted to an rvalue of an integer type. The conversion truncates; that is, the fractional part is discarded. The behavior is undefined if the truncated value cannot be represented in the destination type.

Follow CodeGalaxy

Mobile Beta

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