Overview

A contiguous sequence of characters terminated by the NUL character (refer to ASCII). Text data is said to be more platform-independent than binary data since it is unaffected by word size or byte ordering.

printf

The syntax for the format placeholder is %[flags][width][.precision][length]specifier.

Flags

FlagDescription
-Left-aligns the output
+Prepends a plus for positive signed-numeric types
Prepends a space for positive signed-numeric types
0Prepends zeros for numeric types
#For g and G, trailing zeros are not removed. For f, F, e, E, g, and G, output always has a decimal point. For o, x, and X, the text 0, 0x, and 0X is prepended to nonzero numbers respectively.

Length

LengthDescription
hhint sized integer argument promoted from a char
hint sized integer argument promoted from a short
llong sized integer argument
lllong long sized integer argument
zsize_t sized integer argument

Specifiers

SpecifierDescription
d, ia decimal signed int
ua decimal unsigned int
x, Xa hexadecimal unsigned int
oan octal unsigned int
f, Fa double in fixed-point notation
e, Ea double in standard notation
g, Ga double in normal or standard notation
sa NUL-terminated string
ca char character
pvoid* address in an implementation-defined format

Escape Sequences

C has a standard for processing different escape sequences. Many languages built with C in mind parse these escape sequences in a similar way.

  • \ooo: Consists of one to three octal digits.

    • Bash supports this sequence as $'\ooo'.
  • \xhh: Consists of one or more hexadecimal digits. The x prefix is required to distinguish from octal escape sequences.

    • Bash supports this sequence as $'\xhh'. One or two digits is supported.
  • \uhhhh: Introduced in C11 to represent Unicode code points. Must have exactly four hexadecimal characters specified with 0 leading padding if necessary.

    • Bash supports this sequence as $'uhhhh'. One to four hex digits is supported.
  • \Uhhhhhhhh: Introduced in C11 to represent larger unicode code points. Must have exactly eight hexadecimal characters specified with 0 leading padding if necessary.

Copying Functions

The two primary functions used for copying memory are memcpy and memmove:

void* memcpy(void* restrict s1, const void* restrict s2, size_t n);
void* memmove(void* s1, const void* s2, size_t n);

Bibliography