Unsigned vs Signed Data Types
C++
Medium
6 views
Problem Description
Compare behavior of signed and unsigned integers, especially with negative values. This shows two's complement representation.
Logic: Assign negative value to unsigned and observe result
Official Solution
void question8_signed_unsigned() {
int signedNum = -10;
unsigned int unsignedNum = signedNum;
cout << "Signed value: " << signedNum << endl;
cout << "Same bits as unsigned: " << unsignedNum << endl;
cout << "Unsigned interprets differently!" << endl;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!