How to print long int in c 

Joined:
01/15/2009
Posts:
87

June 30, 2011 15:15:50    Last update: June 30, 2011 15:15:50
You have to add the l flag to printf, otherwise it prints the truncated int:
#include <stdio.h>

int main() {
    long i = 0x6162636465666768L;
    printf("Truncated value of i: %d\n", i);
    printf("Truncated value of i: %d\n", 0x65666768);
    printf("True value of i: %ld\n", i);
}

Prints:
Truncated value of i: 1701209960
Truncated value of i: 1701209960
True value of i: 7017280452245743464


Share |
| Comment  | Tags