LearnFrenzy
Sign in Take a free test

C Library Functions · Predict the Output · Question 11

strftime on time_t 0 with gmtime Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 11 Back to Exercise

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 Correct
  • B 01 Jan 1900, Monday
  • C 00 Jan 1970, Thursday
  • D 01 Jan 1970, Sunday
Correct Answer: Option A

time_t 0 is the Unix epoch, midnight UTC on Thursday 1 January 1970. gmtime avoids any dependence on the local time zone.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links