-1
85         // decimal
0213       // octal
0x4b       // hexadecimal
30         // int
30u        // unsigned int
30l        // long
30ul       // unsigned long

I'm new to C++. What's the difference between int (30) and decimal (85) in this tutorial?

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
hanseN
  • 93
  • 1
  • 1
  • 7
  • @Qantas94Heavy This sentence is in another section! It is about decimal floating-point literals. What does that have to do with this? – Pascal Cuoq Jul 05 '14 at 23:22
  • @PascalCuoq: I thought the OP used the word "decimal" to describe a number with decimal places, not a base 10 integer. – Qantas 94 Heavy Jul 05 '14 at 23:25
  • 1
    Could you please ask a clear question, without resource to external links? – juanchopanza Jul 05 '14 at 23:26
  • 1
    I don't know why this question getting so many downvotes. Seems a reasonable question to me. – Neil Kirk Jul 05 '14 at 23:38
  • 1
    I like how the tutorial introduces `#define` before `const` and doesn't even attempt to steer the reader away from using `#define`. Also, *An array name is a constant pointer to the first element of the array.* and *It is legal to use array names as constant pointers, and vice versa.* Please go find an actual [book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). This isn't working. – chris Jul 05 '14 at 23:45
  • @NeilKirk It was originally so poorly formatted that you would have been excused for thinking that the question was why `0213` was “decimal”. Bad formatting may be excusable for a first question, but people here have become allergic to low-quality questions because there are so many of them, I guess. – Pascal Cuoq Jul 05 '14 at 23:46

3 Answers3

6

The table you are reading from the tutorial is not clear. It should be represented as two tables:

Integer constants can be in one of three bases:

85         // decimal
0213       // octal
0x4b       // hexadecimal

They can have a suffix to indicate a minimum type rank and signedness:

30         // int
30u        // unsigned int
30l        // long
30ul       // unsigned long

You can write a hexadecimal long constant as 0x1234l.

This would also be a good place in the tutorial to say that the suffixes l or ll, when used, only indicate a minimal type rank and that the integer constant will be attributed a wider type if it does not fit in the indicated type.

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
  • I'm not familliar with long and unsigned and unsigned long but if i got it right, 30 is also decimal? – hanseN Jul 06 '14 at 00:00
  • @hanseN Yes, 30 is decimal because it does not have any `0` or `0x` prefix. The prefix (if any) indicates the base. No prefix indicates base 10. – Pascal Cuoq Jul 06 '14 at 00:02
2

30 and 85 are both decimals and integers (type int). The two are not mutually exclusive.

Neil Kirk
  • 21,327
  • 9
  • 53
  • 91
1

Quote :

85         // decimal
0213       // octal
0x4b       // hexadecimal
30         // int
30u        // unsigned int
30l        // long
30ul       // unsigned long

Here the three top lines show how to write a number's value in the desired base. The four remaining lines describe suffixes to distinguish types.

int happens to have no suffix.

Quentin
  • 62,093
  • 7
  • 131
  • 191