KelvinS
KelvinS

Reputation: 3061

qDebug prints a wrong number

I'm just trying to print a number using qDebug as follows:

qDebug() << QString::number(03001);

But the result is:

"1537"

If I try to print without the first zero:

qDebug() << QString::number(3001);

The result is correct:

"3001"

Why does it happen?

I'm using Qt 5.3.

Upvotes: 1

Views: 896

Answers (2)

AMA
AMA

Reputation: 4214

Leading zero will make the number to be interpreted as an octal literal.

octal-literal is the digit zero (0) followed by zero or more octal digits (0, 1, 2, 3, 4, 5, 6, 7)

So this is not by any means related to qDebug, but to the way C++ interprets integer constants.

Upvotes: 5

Silicomancer
Silicomancer

Reputation: 9156

03001 is an octal number in C++.

Upvotes: 1

Related Questions