Hinweis: Videofortschritt und Quizantworten werden nur nach Login gespeichert.

Effizientes Debugging

GCC Warning-Flags

strange.c

#include <stdbool.h>
#include <stdio.h>

char* func(int arg) {
    if (arg = 0) { return "A"; }
    else { return "B"; }
}

int main(int argc, char** argv) {
    printf("%i argument(s) to \"%s\".\n", argc, argv[0]);

    const char* answer = "";
    bool x = (argc <= 1) ? false : true;
    int y = (argc <= 1) ? 1 : 0;

    // Teil 1
    if (y || x && x) { answer = "A"; }
    else { answer = "B"; }
    printf("1 - %s\n", answer); // Answer A or B?

    // Teil 2
    switch (y) {
        case 1: answer = "A";
        case 0: answer = "B";
        default: answer = "C";
    }
    printf("2 - %s\n", answer); // Answer A, B or C?

    // Teil 3
    answer = func(x);
    printf("3 - %s\n", answer); // Answer A or B?

    // Teil 4
    int a;
    if (a == x) { answer = "A"; }
    else { answer = "B"; }
    printf("4 - %s\n", answer); // Answer A or B?

    return 0;
}

Material

Creative Commons License Video und Material von Benjamin Rickels et al. lizenziert unter CC BY-NC-SA 4.0.