FORMAT SPECIFIERS

SPECIFIER    DATA TYPE    DESCRIPTION                               EXAMPLE OUTPUT
%hd          short int    used to print values of short integers    printf("%hd", var);

%zu          size_t       specifier for size_t returned by sizeof   printf("%zu", sizeof(arrayName);

%[^\n]                    read characters until \n is encountered   scanf("[^\n]", sentence); 

%lu                       can be used to display memory location    printf("%lu \n", &arrayname[i][j]);
                          the & operator is used to print the
                          address

%[^\n]%*c                 used to read the entire line, including   scanf("%[^\n]%*c", filename);
                          spaces, until newline. it works great for
                          file names, titles, or sentences.
                           - think of this as a clever way of
                             implementing %s
 
 * The %[^\n] format specifier instructs scanf() to read characters until it encounters
   a newline character and stores them in the sentence array. 
 
 * when using %hd with there might not be a noticeable difference since short 
   is promoted to int by printf
   
 * size_t is a typedef that represents an unsigned integer type that is guaranteed to 
   be large enough to hold the size of any object in memory
    - size_t is just an alias!
       - On a 32-bit system, size_t might be unsigned int
       - On a 64-bit system, size_t might be unsigned long or unsigned long long

Last updated