C ++ has accumulated 20161015 million syntaxes and 20161015 million syntaxes.

Source: Internet
Author: User

C ++ has accumulated 20161015 million syntaxes and 20161015 million syntaxes.

1. break: Used to terminate the current loop (jump out of the loop body ).

The most common problems are the usage in a double-layer loop:

(1) When a break occurs in the inner cyclic body, the inner cyclic body jumps out and executes the outer cyclic body again.

(2) In the External Loop body, break is parallel to the internal loop body and encounters and jumps out of the External Loop body.

Note: When break is used in the switch statement, the switch is directly jumped out.

Break cannot be used directly in if, unless if is a loop sentence, but its function is loop, not if

Refer:

Http://blog.csdn.net/wfz0704112/article/details/8550230

Http://blog.csdn.net/u010738823/article/details/48896077

2. ctime header file

Concepts of "time" and "date"

Coordinated Universal Time (UTC ):

Coordinated Universal Time, also known as the World Standard Time, is known as the Greenwich Mean Time (GMT ). for example, the time difference between mainland China and UTC is + 8, that is, UTC + 8. america is UTC-5

 

Calendar Time:

Calendar time: the time expressed by "the number of seconds elapsed from a standard time point to the current time. this standard time point varies with compilers, but for a compilation system, this standard time point remains unchanged, the calendar time corresponding to the time in the compilation system is measured by the standard time point. Therefore, it can be said that the calendar time is relative time, But no matter which time zone you are in, the calendar time is the same for the same standard time point at the same time point. epoch: the time point is an integer in the Standard C/C ++. It is expressed by the number of seconds (calendar time) between the time and the standard time point.

 

Clock tick:

A clock timing unit (not called a tick answer) is controlled by the CPU. A clock tick is not a clock cycle of the CPU, but a basic unit of time for C/C ++.

 

Important macros

CLOCKS_PER_SEC

Note: The number of tick answers per second

Definition:

     #define CLOCKS_PER_SEC ((clock_t) 000)

Purpose: it is used to indicate the number of clock units in one second.

 

Clock_t

Description: The Tick count type.

Definition:

 #ifndef _CLOCK_T_DEFINED    typedef long clock_t; #define _CLOCK_T_DEFINED #endif

Note: clock_t is the data type used to save the time.

 

Time_t

Description: The second count of the calendar time.

Definition:

# Ifndef _ TIME_T # define _ TIME_T // avoid repeatedly defining time_t typedef long time_t; // The Time Value time_t is the alias of a long integer # endif

Note: For a value of the time_t data type, it indicates that the time cannot be later than 09:04:07 from January 1, 2038 to October 8.

Important data types

Struct tm

Description: time segment data structures such as year, month, and day

 

Struct tm {int tm_sec; // Seconds. [0-60] (leap second) int tm_min; // Minutes. [0-59] int tm_hour; // Hours. [0-23] int tm_mday; // Day. [-3] int tm_mon; // Month. [0-] int tm_year; // Year-900. int tm_wday; // Day of week. [0-6] int tm_yday; // Days in year. [0-365] int tm_isdst; // DST. [-/0/] # ifdef _ USE_BSDlong int tm_gmtoff; // Seconds east of UTC. _ const char * tm_zone; // Timezone abbreviation. (abbreviated time zone) # elselong int _ tm_gmtoff; // Seconds east of UTC. _ const char * _ tm_zone; // Timezone abbreviation. # endif };

  

Function

Clock Function

Prototype: clock_t clock (void );

Purpose: return the time unit for the program to start and pass.

Difftime Function

Prototype: double difftime (time_t timer, time_t timer0 );

Purpose: return the difference between two calendars: timer-timer0;

Time Function

Prototype: time_t time (time_t * timer );

Purpose: Obtain the Time of the host.

NOTE: If timer is not empty, the return value is also assigned to the variable pointed to by timer.

Mktime Function

Prototype: time_t mktime (struct tm * timeptr );

Function: converts the time segments composed of years, months, days, minutes, And seconds to the calendar time composed of the elapsed seconds.

Localtime Function

Prototype: struct tm * localtime (const time_t * timer );

Function: converts a calendar time to a local subdivision time.

Gmtime Function

Prototype: struct tm * gmtime (const time_t * timer );

Purpose: Convert the calendar time to the time segment of UTC (coordinated world time ).

Note: localtime and gmtime are 8 hours more than the latter.

Asctime Function

Prototype: char * asctime (const struct tm * timeptr );

Purpose: Convert the time segment to a short string.

Ctime Function

Prototype: char * ctime (const time_t * timer );

Purpose: Convert the calendar time to a short string.

Strftime Function

Prototype: size_t strftime (char * strDest, size_t maxsize, const char * format, const struct tm * timeptr );

Purpose: format the time segment according to the format requirement to the buffer zone pointed to by strDest.

The strftime () function is similar to sprintf (): recognizes the command set starting with the percent sign (%), and formats the output result in a string. the formatting command specifies the exact representation of various date and time information in strDest. other characters in the format string are put in the string as they are. format Commands are listed below, which are case sensitive

% A abbreviation of the day of the week

% A full name of the day of the week

Abbreviation of % B month

% B full name

% C standard date time string

The last two digits of the Year % C

% D indicates the day of the month in decimal format.

% D month/day/year

% E indicates the day of the month in decimal format in the two-character field

% F-month-day

The last two digits of the Year % g. The year is based on the week.

% G year, based on the week Year

% H abbreviated month name

% H in 24-hour format

% I hour in 2-hour format

% J indicates the day of the year in decimal format.

Month in % m decimal format

% M decimal number of minutes

% N new line operator

% P equivalent display of local AM or PM

% R 2 hours

% R display hours and minutes: hh: mm % S decimal seconds

% T horizontal tab % T: hh: mm: ss

% U the day of the week, Monday is the first day (value ranges from 0 to 6, Monday is 0)

% U indicates the week of the year. Sunday is regarded as the first day (the value ranges from 0 to 53)

% V indicates the week of the year, which is based on the year of the week.

% W decimal indicates the day of the week (the value ranges from 0 to 6, and Sunday is 0)

% W indicates the week of the year. Monday is the first day (from 0 to 53)

% X standard date string

% X standard time string

% Y does not contain the century's decimal year (the value ranges from 0 to 99)

% Y indicates the tenth year of the century.

% Z, % Z Time Zone name. If the time zone name cannot be obtained, an empty character. % percent is returned.

Relationship Diagram

 

Application

# Include <iostream> # include <ctime> using namespace std; // defines the time (in milliseconds) consumed by the macro to calculate the algorithm. // "\" Symbol: Continue character. Indicates that the row is connected to the next row # define BEGIN_RECODE \ {\ clock_t _ temp_begin_time _; \__ temp_begin_time = clock (); \ # define END_RECODE (dtime) \ dtime = float (clock ()-_ temp_begin_time _)/CLOCKS_PER_SEC ;\} int main () {float tim; int I; for (I = 0; I <100000; I ++) {a [I] = int (rand () % 100000);} cout <"10 W Number of hill sorting:" <endl; BEGIN_RECORD shellSort2 (a, sizeof (a)/sizeof (int); END_RECORD (tim) cout <"Hill incremental sequence running time: "<tim <" s "<endl; for (I = 0; I <100000; I ++) {a [I] = int (rand () % 100000);} BEGIN_RECORD shellSort (a, sizeof (a)/sizeof (int); END_RECORD (tim) cout <"Hibbard incremental sequence running time: "<tim <" s "<endl; cin. get (); return 0 ;}

 

Reference

Http://www.cnblogs.com/dongzhuangdian/p/5468608.html

Http://www.cnblogs.com/kzloser/archive/2012/07/17/2594773.html

Http://www.cnblogs.com/leoin2012/p/3910889.html

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.