-3

Just started learning c. And I noticed that there are 2 format specifiers for int.

%i
%d

I like to use %i (The i of integer). But I see most people use %d. Is there like a rule or something (like you have rules for variable naming (camelCase or underscores etc.)).

I allready noticed this question but it did not really help.

But this is not my question. My question was which one is more commonly used. And which one should I pick. My question is not wat is the difference. If you look good at these questions you see that in the other question there is nothing about which one is more commonly used they just say it is interchangeble.

Is it just so that you can choose. Is one of them more common to use or recommanded?

Community
  • 1
  • 1
Tristan
  • 2,000
  • 17
  • 32

1 Answers1

1

They are the same. Use whichever one you like. One stands for "integer" and the other stands for "decimal".

At a guess, there are two from early, conflicting implementations. And I'm talking like half a century ago.

I use %d and, to be honest, I haven't the faintest idea why.

They mean different things for scanf, though!

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • Only for `printf`. – Quirk Jun 10 '16 at 18:06
  • @Quirk The question is tagged [tag:printf]. Might as well also say "only for programming languages" :D – Lightness Races in Orbit Jun 10 '16 at 18:07
  • I know it's tagged as such. But as long as I don't see it mentioned explicitly in the question, I think let's be pedantic. But you'd know better. – Quirk Jun 10 '16 at 18:08
  • Oke I understand it. I already read the stuff about scanf so I understand that too. It is a bit confusing because in C# a decimal value is like a value with a lot of commas(larger then a double). – Tristan Jun 10 '16 at 18:08
  • @TristanT: Yeah, best not to think about other languages when rationalising :) You'll find plenty of differences. – Lightness Races in Orbit Jun 10 '16 at 18:09
  • Isn't this left over FORTRAN 77 fun? – Michael Dorgan Jun 10 '16 at 18:12
  • 1
    Given the fact that, as @Quirk observed, the two field specifiers have different meaning (than each other) to `scanf()`, I'd be inclined to guess that `printf()` supports both so that the same format strings can be used with both `scanf()` and `printf()`, without sacrificing either of the two distinct behaviors they provide to `scanf()`. – John Bollinger Jun 10 '16 at 18:17
  • @JohnBollinger: Maybe. Can't think of many scenarios in which output and input need to be identical though. – Lightness Races in Orbit Jun 11 '16 at 13:24