samedi 27 décembre 2014

weird gcc behavior with unsigned ints


#include<iostream>
#include<fstream>
#include<cstdint>

using namespace std;

int main()
{
uint16_t ii;
cin >> ii;
printf("%d\n",(uint8_t)ii);
}


when i give input as 5 the output is also 5. But when i change "ii" declaration to be of type uint8_t, i do not get 5 but 53 which seemed to be ascii value of 5. Is this expected?


Aucun commentaire:

Enregistrer un commentaire