Unsigned long with negative value
        Posted  
        
            by egiakoum1984
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by egiakoum1984
        
        
        
        Published on 2010-03-16T15:45:06Z
        Indexed on 
            2010/03/16
            15:51 UTC
        
        
        Read the original article
        Hit count: 365
        
Filed under: 
        c
Please see the simple code below:
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(void)
{
    unsigned long currentTrafficTypeValueDec;
    long input;
    input=63;
    currentTrafficTypeValueDec = (unsigned long) 1LL << input; 
    cout << currentTrafficTypeValueDec << endl;
    printf("%u \n", currentTrafficTypeValueDec);
    printf("%ld \n", currentTrafficTypeValueDec);
    return 0;
}
Why printf() displays the currentTrafficTypeValueDec (unsigned long) with negative value?
The output is:
9223372036854775808
0
-9223372036854775808 
© Stack Overflow or respective owner