logo

Useful tips for using printf in C

#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char* argv[]) { int a = 199; printf("%d\n", a); printf("%x\n", a); printf("%X\n", a); printf("%#X\n", a); printf("%8d\n", a); printf("%08d\n", a); float b = 15.3; printf("%f\n", b); printf("%.2f\n", b); unsigned int c = 20; printf("%u\n" c); long long d = 100; printf("%lld\n", d); unsigned long long e = 100; printf("%llu\n", e); printf("%llu\n", sizeof(e)); char f = 'a'; printf("%c\n", f); int* p = &a; printf("%p\n", p); return 0; }
Course thumb

The C programming language made simple