LearnFrenzy
Sign in Take a free test

C Library Functions · Exercise 2 of 4

C Library Functions 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, so the answers are the real output.

Question 11 Medium

What is the output of the following C program?

main.c
#include <stdio.h>
#include <time.h>

int main(void) {
    time_t t = 0;
    char buf[40];
    strftime(buf, sizeof buf, "%d %b %Y, %A", gmtime(&t));
    puts(buf);
    return 0;
}
A 01 Jan 1970, Thursday
B 01 Jan 1900, Monday
C 00 Jan 1970, Thursday
D 01 Jan 1970, Sunday
Question page & discussion
Question 12 Hard

What is the output of the following C program?

main.c
#include <stdio.h>
#include <string.h>

int main(void) {
    char d[6] = "XXXXX";
    strncpy(d, "ab", 4);
    printf("%s %d %d %c\n", d, d[2], d[3], d[4]);
    return 0;
}
A ab 0 0 X
B abXXX 88 88 X
C ab 0 88 X
D ab 0 0 0
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