1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>

int main(int argc, char* argv[]) {
    int dec = 41;
    printf("dec = %d\n", dec);
    int hex = 0x29;
    printf("hex = %d\n", hex);
    int oct = 051;
    printf("oct = %d\n", oct);
    int ch = ')';
    printf("ch = %d\n", ch);


    printf("dec to hex = %x\n", dec);
    printf("dec to oct = %o\n", dec);
    printf("dec as char = %c\n", dec);

    // BAD code quality: should use a character constant when printing characters
    printf("ch from int constant %c\n", 41);
    // FIXED code quality: using a character constant
    printf("ch from char constant %c\n", ')');
    return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

© Copyright 2024 Alexander J. Quinn & David Burnett         This content is protected and may not be shared, uploaded, or distributed.