Using char for small integer (C++) -



Using char for small integer (C++) -

i read 1 can utilize "char" little integers. however, when try,

unsigned char = 4; std::cout << << std::endl;

it gives character, not 4.

what experiencing effects of operator overloading. << operator assumes want print character when hand variable of type char, hence behaves differently expect integral variables.

as suggested vivek goel can forcefulness compiler select overload want:

unsigned char = 4; std::cout << static_cast<unsigned int>(a) << std::endl;

addendum: unless working on environment severely constrained resources (esp. tiny memory), optimising on wrong end. operations on unsigned int typically faster on unsigned char, because processor cannot fetch single bytes has @ to the lowest degree multiple of 4 , mask out other 3 bytes.

c++ integer char

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -