C ++ Primer

Source: Internet
Author: User

C ++ Primer
1 program = algorithm + Data


2 Structured Programming
C process-oriented algorithm


3. Object-Oriented Programming
C ++ object-oriented emphasis on data
Class is a standard that describes the data format
Class = Data + algorithm + object-oriented features (encapsulation, inheritance, polymorphism)


4. Generic programming
Independent from data type emphasizing Algorithms


5 sizeof
Sizeof is an operator that must be enclosed in parentheses for the type and optional for variable parentheses.
For example:

Long lnum; cout <sizeof (int) <endl; cout <sizeof lnum <endl; // cout may not be enclosed in brackets <sizeof (lnum) <endl;


6 braces initialize
// C ++ 98: int n1 = {24}; // assign a 24 // C ++ 11: int n2 {24} to n1 }; // The equal sign can also be omitted int n3 {}; // if no value is specified, the initialization is 0.


7 pointer Declaration
Int * p1; // in C, it is emphasized that * p1 is of the intint * p2 type; // in C ++, it is emphasized that the p2 type is int * p3; // recommended statement


8. latency Functions
Clock () returns the system time after the program starts execution,
There are two problems:
1 The unit of clock () return value is not necessarily second;
Solution:
CLOCKS_PER_SEC, the number of system time units per second.
2. the return value type may be long or unsigned long, which is determined by the operating system;
Solution:
Clock_t type, which is defined as the type used by the system.


#include 
 
  #include 
  
   void main(){    int sec;    printf("Enter the delay time in seconds:");    scanf("%d", &sec);    clock_t delay = sec * CLOCKS_PER_SEC;    printf("start...\a\n");    clock_t start = clock();    while(clock() - start < delay);    printf("done\a\n");}  
  
 



The program converts seconds to the system time unit to avoid converting the system time to seconds for each cycle, which is more efficient.


9 C ++ 11 class initialization
class Classy {int m_mem1 = 10;};


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.