c++ - Why does shifting more than the allowed bits still work? -


i have int8_t , wanted see happen if shift left further 8 bits. did:

int8_t x = 1;  std::cout << (x << 10); 

for reason returns 1024 if type contained enough bits represent number. thought when shift more given bits 0 in bits (or signed overflow/underflow leads undefined behavior). also, ran code give me maximum number of int8_t:

std::numeric_limits<int8_t>::max(); // 127 

the max number of type 127 shifting left can make go higher unsigned type! how possible?

the arguments << being implicitly widened int, , result of x << 10 int.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -