The C Programming Language Chapter-1

Chapter-1 A Tutorial Introduction

Notes of The C programming Language

Integer Division of C

In C, integer division will truncate the result to zero, regardless of whether the result is positive or negative.

printf Conversion Specification %f

For example, %6.4f means printf should print the value as floating point, at least 6 characters wide (it means the total width) and 4 after the decimal point.

1
2
3
4
5
6
7
8
9
#include <stdio.h>

int main() {
float printFloatWidth1 = 1111.222;
float printFloatWidth2 = 0.2;
printf("printFloatWidth1: %6.4f\n", printFloatWidth1);
printf("printFloatWidth2: %6.2f\n", printFloatWidth2);
return 0;
}
1
2
printFloatWidth1: 1111.2220
printFloatWidth2: 0.20

If the valid digits of the value cannot fill the least width, printf will fill it with spaces, as illustrated in printFloatWidth2.

Read more