Program --- C language details 17 (calculate the maximum value of time_t, strlen calculates the length, malloc allocates characters memory details, and switch's default details)

Source: Internet
Author: User

Program --- C language details 17 (calculate the maximum value of time_t, strlen calculates the length, malloc allocates characters memory details, and switch's default details)

Main Content: calculate the maximum value of time_t, strlen evaluate the length, malloc allocate character memory details, switch default details

# Include
 
  
# Include
  
   
Int main () {/************************************** * ************************* time_t maximum value test ********** **************************************** * **************/time_t biggest = 0x7fffff; printf ("biggest = % s", ctime (& biggest);/* The ctime () function converts the parameter to the local time. Here is a detail. I have no line breaks in printf, however, the output has a line break. The following test ctime (& biggest) returns the string containing '\ n' indeed */char * test = ctime (& biggest ); while (* test ++) {if (* test = '\ n') printf ("find '\\ N' int test \ n ");} // printf (" biggest = % s \ n ", asctime (gmtime (& biggest ))); // The correct statement is this sentence, the above statement has a time difference problem /********************************* * ******************************* strlen () function Testing ************************************** * **************************/char * a = "abc "; printf ("strlen = % d \ n", strlen (a); // strlen evaluate the string length, excluding the most '\ 0' malloc (strlen ()); // This is not correct, because malloc (strlen (a) + 1) should be used; memory for '\ 0' to be applied /************ **************************************** * ************ Switch test result description: default can be placed anywhere in the switch ********************************* * *******************************/int B = 2; const int c = 2; // Add case c: printf ("c") to the switch. You can test that the c modified by const is not a constant switch (B) {case 0: printf ("case: 0 \ n"); 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; used to jump out of the nearest loop or switch statement, then continue executing} printf ("after break, the program run here! \ N "); break;} return 0 ;}
  
 

Output:


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.