What will be the output of the following C code if the system time is 4:27 PM? [code]#include<stdio.h> #include<time.h> int main() {

Lâm Phung

New member
What will be the output of the following C code if the system time is 4:27 PM?
Code:
#include<stdio.h>
#include<time.h>
int main()
{
    struct tm *ptr;
    time_t t;
    char str[100];
    t = time(NULL);
    ptr = localtime(&t);
    strftime(str,100,"%H %p %M minutes",ptr);
    puts(str);
    return 0;
}
A. 16 27 minutes
B. 4 27 minutes
C. 16 PM 27 minutes
D. 4 PM 27 minutes
 
Answer: c
Explanation: %H is a format specifier used to represent the hours (0-23) and %I specifies the hours in the format(0-12), %p is used to specify AM or PM, %M is used to specify the minutes. Hence output will be: 16 PM 27 minutes
 

Tìm kiếm

Back
Top