| intro/printf-types-with-explanations.c - Udskrivning af variable af forskellige typer med printf - med forklaringer. | Lektion 2 - slide 21 : 24 Program 2 |
#include <stdio.h>
int main(void) {
int i = 10;
short j = 5;
long k = 111L;
printf("i: %d, j: %3hd, k: %10.5ld\n", i, j, k);
/* i: %d Simple printing of an integer. %i can also be used (same meaning).
j: %3hd Minimum field width is 3. h is size modfier for short int.
k: %10.5ld Minimum field width is 10. At least 5 ciffers must be printed.
l is size modifier for long int.
\n forces print of a new line char.
*/
double x = 10.5;
float y = 5.5F;
long double z = 111.75L;
printf("x: %f, y: %5.2f, z: %Le\n", x, y, z);
/* x %f Simple printing of double.
y: %5.2f Printing of float. Same conversion letter as double. Minimum field width is 5.
Number of digits after decimal point is 2.
z: %Le Printing af long double. L is size modifier for long.
e is conversion letter for scientific notation:
\n forces print of a new line char.
*/
char c = 'A';
char d = 'a';
printf("c: %c, d: %d\n", c, d);
char *s = "Computer", *t = "C";
printf("s: %s,\nt: %s\n", s, t);
return 0;
}