OA. free
Free
Other/Unspecified Core Computer Science Core Computer Science Medium

What will be the output of the following C code snippet if the file "output.txt" is empty...

Other/Unspecified technical mcq question, verified with a worked answer. Free to practise - no sign-up.

What will be the output of the following C code snippet if the file "output.txt" is empty before the program is run?

int main() {
    FILE *file = fopen("output.txt", "w");
    if (file != NULL) {
        int num = 250;
        fprintf(file, "%#x %#X", num, num);
        fclose(file);
    }
    file = fopen("output.txt", "r");
    char str[20];
    if (file != NULL) {
        fgets(str, sizeof(str), file);
        printf("%s", str);
        fclose(file);
    }
    return 0;
}
Choose one option.
Show answer & explanation
Answer: A. A) 250 250

Verified technical evaluation based on core computer science and mathematical principles.

Step-by-step Derivation:
Step 1: Parse problem constraints.
Step 2: Compute verified solution.
Step 3: Select matching option.