User Tools

Site Tools

Return to Home page


This shows you the differences between two versions of the page.

Link to this comparison view

cs:c_language:printf_format_inttypes.h [2019/02/26 14:35]
cs:c_language:printf_format_inttypes.h [2019/02/26 14:35] (current)
Line 1: Line 1:
 +====== Printf format <​inttypes.h>​ ======
 +Use of the function ''​printf''​ to format the output of variables with fixed dimension, as defined in the ''<​inttypes.h>''​ library.\\
 +The ''<​inttypes.h>''​ library allows the definition of variables with a fixed dimension in terms of //number of occupied bits//. For instance, the type ''​uint64_t''​ declares an ''​unsigned integer''​ variable with dimension 64 bits, and the ''​int64_t''​ can be used to declare a ''​signed integer''​ variable with dimension 64 bits. Other possible types of the library are: ''​uint32_t'',​ ''​int32_t'',​ ''​unit16_t'',​ ''​int16_t'',​ ''​uint8_t''​ and ''​int8_t''​.\\
 +For printing ''​uint32_t'',​ ''​int32_t'',​ ''​unit16_t'',​ ''​int16_t'',​ ''​uint8_t''​ and ''​int8_t''​ the typical ''​%u''​ and ''​%d''​ operators of the ''​printf''​ function can be used, instead, to print ''​uint64_t''​ or ''​int64_t''​ we have to make use of specific macros defined in ''<​inttypes.h>''​. See the example.
 +<file C inttypes.c>​
 +/* Example of use of the function printf to format the output of variables with fixed dimension, as defined in the ''<​inttypes.h>''​ library */
 +#include <​stdio.h>​
 +#include <​inttypes.h>​
 +int main() {
 +  int64_t a = -3;
 +  uint64_t b = 3;
 +  int8_t c = -3;
 +  printf("​a=%"​ PRId64 " b=%" PRIu64 " c=%d\n",​ a, b, c);
 +  ​
 +  return 0;
 +As can be see in the example, the macros ''​PRId64''​ and ''​PRIu64''​ can be used to print ''​int64_t''​ and ''​uint64_t'',​ respectively.\\
 +Macro ''​PRIx64''​ can also be used to print hexadecimal.

If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at]

You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url:
/web/htdocs/ ยท Last modified: 2019/02/26 14:35 (external edit)

Privacy Policy