CSC231 Comparing Signed and Unsigned Numbers in C++

From dftwiki3
Jump to: navigation, search

--D. Thiebaut (talk) 06:50, 18 November 2014 (EST)


Source


/* compare2sComplement.cpp
// D. Thiebaut
// Illustration of comparison of signed and unsigned ints
// To compile and run this program:
//
//     g++ compare2sComplement.cpp
//     ./a.out
//
*/

#include <stdio.h>

int main() {

    unsigned int x = 0xFFFFFFFF;
    unsigned int y = 15 ;
    //int x = 0xFFFFFFFF;
    //int y = 15 ;

    printf( "x = %u\n", x );
    printf( "y = %u\n", y );

    //printf( "x = %d\n", x );
    //printf( "y = %d\n", y );

    if ( x < y ) 
        printf( "x < y\n\n" );
    else
        printf( "x > y\n\n" );

    return 0;
}



...