0Pricing
C Academy · Lesson

Width, Precision, Flags

Control formatting.

Controlling Output Width

A number after % sets the minimum field width. The value is right-aligned and padded with spaces.

#include <stdio.h>
int main(void) {
    printf("[%5d]\n", 42);
    return 0;
}

Left Alignment

A - flag left-aligns the value within the field.

#include <stdio.h>
int main(void) {
    printf("[%-5d]\n", 42);
    return 0;
}

All lessons in this course

  1. printf Format Specifiers
  2. scanf and Input
  3. Width, Precision, Flags
  4. Common I/O Pitfalls
← Back to C Academy