0

#include <stdio.h> int main() { unsigned char x=300; printf("%d",x); }

Anyone please explain me the concept of unsigned

19th Jul 2019, 5:10 PM
Rohit Ahuja
Rohit Ahuja - avatar
5 Respostas
+ 7
unsigned char datatype range from 0 to 256. So, when you want to initialized 300, it takes it (300-256)=44. That's why the result is 44
19th Jul 2019, 7:23 PM
Aparesh Bhunia
Aparesh Bhunia - avatar
+ 7
Also after reading other answers, run this code. You will get it what happens. #include <iostream> using namespace std; int main() { int i = 200; for(unsigned char c = 200; c < 350; c++) cout << "int: " << i++ << ", unsigned char: " << (int)c << "\n"; return 0; }
19th Jul 2019, 9:50 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 5
Generally data types goes from negative A-1 to positive A. Unsigned free up first bit that is used for sign and doubles range of positive values. for example if a Data type can take values from -127 to 128. An unsigned Data type will go from 0 to 256.
19th Jul 2019, 5:20 PM
Lighton
Lighton - avatar
+ 1
Thanks aparesh bhunia
20th Jul 2019, 6:20 AM
Rohit Ahuja
Rohit Ahuja - avatar
0
The answer is 44 why?
19th Jul 2019, 5:11 PM
Rohit Ahuja
Rohit Ahuja - avatar