Monday, November 5, 2012

unsigned Keyword in C/CPP


Simple note:

Code:

#include <iostream>
using namespace std;

/** test unsigned keyword,
 * use char to test it since its range is fixed ( 1 byte )
 */
int main() {
    char ch = -1; // signed char, range -128 ~ 127
    unsigned char uch = ch; // unsigned char, range 0 ~ 255
    cout << "\n\tsigned: " << static_cast<int>(ch) << "\n"
        << "\tunsigned: " << static_cast<int>(uch) << "\n\n";
    system("PAUSE");
    return 0;
}



Result:



File at github:

https://github.com/benbai123/C_Cplusplus_Practice/blob/master/CPP/CPP_Basic/unsigned_test.cpp

No comments:

Post a Comment