banner
cells

cells

为美好的世界献上 code

Q152

Q152#

#include <iostream>
#include <type_traits>

int main() {
    if (std::is_signed<char>::value) {
        std::cout << std::is_same<char, signed char>::value << std::endl;
    } else {
        std::cout << std::is_same<char, unsigned char>::value << std::endl;
    }
    return 0;
}

Explain#

Plain char, signed char, and unsigned char are three distinct types (...).

#include <iostream>
#include <type_traits>

int main() {
    std::cout << std::is_signed<char>::value << std::endl; // 1
    std::cout << std::is_unsigned<char>::value << std::endl; // 0

    std::cout << std::is_same<char, signed char>::value << std::endl; // 0
    std::cout << std::is_same<char, unsigned char>::value << std::endl; // 0
    std::cout << std::is_same<signed char, unsigned char>::value << std::endl; // 0
}

Answer#

click to see answer 0
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.