Program Ape---C language details 17 (the maximum value for time_t, strlen for length, malloc to allocate character memory details, switch in default details)

Source: Internet
Author: User
Tags local time

Main content: The maximum value of the time_t, the strlen is the length, malloc allocation character memory details, switch in the default details

#include <stdio.h> #include <time.h>int main () {    /************************************         time_t max Test     **************** /    time_t biggest = 0x7fffffff;        printf ("biggest =%s", CTime (&biggest)); /* CTime () function converts the parameter to local time, here is a detail, I don't have a newline in printf, but the output is wrapped, and the following test CTime (&biggest) returns a string containing ' \ n ' really */             char *test = CTime (&biggest);    while (*test++)     {         if (*test = = ' \ n ')             printf ("Find ' \\n ' int test\n ");    } //    printf (" biggest =%s \ n ", Asctime (Gmtime (&biggest)));  //Correct statement is this sentence, the above statement has a time difference problem     /************************************************        strlen () function test     *************************** /    char *a = "abc";    printf ("strlen =%d\n", Strlen (a)); //strlen The length of the string, which does not contain the most '     malloc (strlen (a));//This is not true because of the use of malloc (Strlen (a) +1); To apply for '  /*************************************************************** ' memory        **        switch Test          Result Description: Default can be placed anywhere in switch     ******************************************************************/    int b = 2;     const int c = 2; Add Case c:printf ("C") to the switch and you can test that the Const modifier's C is not constant     switch (b)     {        case 0:             printf ("case:0\n");  & nbsp          break;        case 1:              printf ("case:1\n");            break;        default:                              printf ("default\n");            break;        case 2:             printf ("case:2\n");            while (b = = 2)              {                 printf ("B = 1\n");                break;   //break; To jump out of the nearest layer of loops or switch statements, jump out of the loop, and then proceed to the next             }            printf ("after break,the Program Run here!\n ");            break;    }     return 0;}

Output:


Program Ape---C language details 17 (the maximum value for time_t, strlen for length, malloc to allocate character memory details, switch in default details)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.