User Tools

Site Tools


Action disabled: source
cs:c_language:printf_format_inttypes.h
Return to Home page

Printf format <inttypes.h>

Concepts:
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.

Example:

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;
}

Comment:
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] skenz.it

You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/cs/c_language/printf_format_inttypes.h?do=edit
/web/htdocs/www.skenz.it/home/data/pages/cs/c_language/printf_format_inttypes.h.txt · Last modified: 2024/04/08 22:35 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki
Privacy Policy