# Thread: int wrong value being printed?

1. ## int wrong value being printed?

Code:
```int test = 012452;
printf("\n%d", test);```
why is the printed result:

5418

nb: it happens to ints that have a 0 as the first digit ??

2. Zero is false, so in some terms it is skipped, I use C++, so I could be wrong

3. I think 0 in the front means the number is counted as octal.

4. is the only way of getting around it is to make test a string? or can i keep as an int and somehow manipulate it?

5. Originally Posted by Axel
nb: it happens to ints that have a 0 as the first digit ??
Yes, the 0 prefix denotes that the number is represented in the octal number system (See the first line on pg 193, K&R 2nd Edition).

In printf, %d means decimal integer, so it's printing it in the decimal format.

Try printing it in octal form using
Code:
`printf("\n%o", test);`

6. hmm this time it omits the 0..
Code:
```int test =  012345;
printf("\n%o", test);```
12345

7. See the first line on pg 193, K&R 2nd Edition
WT*?

8. Originally Posted by Axel
hmm this time it omits the 0..
Code:
```int test =  012345;
printf("\n%o", test);```
12345
It would have to be this (if I remmember correctly):
Code:
```int test =  012345;
printf("\n%06o", test);```
But I'm not sure if you want to limmit test to just having digits 0-7.

9. Or
Code:
```int main()
{
int test =  012345;
printf("\n%#o", test);
return(0);
}```

10. Or:
Code:
```#include <stdio.h>

int main(void) {
const char *test = "0123456";
puts(test);
return 0;
}```
If you don't know how many zeros precede the number then you're stuck with using a string representation like my sample above.

11. Axel: you know what octal is?

King Mir: it is just an integer. If it's in octal, then its digits are [0-7]. If decimal, then [0-9]. If hex then [0-9a-f]. It's the same integer in either case. Digital representation has nothing to do with the values an integer can take on.

12. that's saying, hey, here, i have a number in octal and on the printf, please represent it in decimal
Code:
`printf("%d", test);`
and by any chance, 5418 is decimal for 12452 in octal