What will be the result of executing the loop with int8_t type?

#include <iostream>
#include <stdint.h>

using namespace std;

int main() {
    int a = 0;
    for (int8_t i = 1; i > 0; i <<= 1)
        a++;
    cout << a;
    return 0;
}
Explanation
int8_t is an 8 bit signed type, the most significant bit of which is responsible for the sign of a number. The loop will end after seven iterations, as the most significant bit is set to one. Therefore, a will be 7.
int8_t is defined in stdint.h
https://en.wikipedia.org/wiki/Stdint.h

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести