-1

If int is 64 bits, can I assume, that %d produces int? What is then %hd, %ld, %lld and what if I want int32_t as output?

Cosinus
  • 31
  • 4

1 Answers1

1

In the "inttypes.h" header are a number of macros for format specifiers to be used for fixed width types, regardless of environment

For a int32_t printed in decimal format, you would use the PRId32 macro. For example:

int32_t x;
printf("x = %" PRId32 "\n", x);

This macro expands to a string containing the d format specifier and any necessary size modifiers. The above code also takes advantage of the compiler merging strings that appear one after the other.

dbush
  • 205,898
  • 23
  • 218
  • 273