LearnFrenzy
Sign in Take a free test

C Input / Output · Exercise 2 of 4

C Input / Output Predict the Output

  • 12 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Read each program and choose what it prints. Every program was compiled and run (with the input shown, where it reads any), so the answers are the real output.

Question 11 Hard

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    FILE *fp = tmpfile();
    if (fp == NULL)
        return 1;
    fputs("abc", fp);
    rewind(fp);
    int count = 0;
    while (!feof(fp)) {
        fgetc(fp);
        count++;
    }
    printf("%d\n", count);
    fclose(fp);
    return 0;
}
A 4
B 3
C 0
D The loop never ends
Question page & discussion
Question 12 Medium

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    char b[6];
    int n = snprintf(b, sizeof b, "%d-%s", 2026, "Nov");
    printf("%d [%s]\n", n, b);
    return 0;
}
A 8 [2026-]
B 5 [2026-]
C 8 [2026-Nov]
D 6 [2026-N]
Question page & discussion
Up next · Exercise 3Find the Error8 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links