Wei-Cheng Liu Wei-Cheng Liu - 1 year ago 76
C Question

On the printf of the C programming language

I type the following C program in Microsoft Visual Studio Community 2015:

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>

void main()
int ni = -27;
printf(":%d: :%o: :%x: :%u:\n", ni, ni, ni, ni);

Then I build and run the .exe file. The output is as follows:

:-27: :37777777745: :ffffffe5: :4294967269:

I can understand the first number is -27, but I can't understand others. Could anyone please provide an answer?

Answer Source

%d : Decimal value

%o : Octal value

%x : Hexadecimal value

%u : Unsigned value

Since your number is signed, depending on the representation there's an overflow or wrap-around. There are plenty of ressources that will teach you that, as it is out of the scope of this site.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download