C-to-C + + upgrade

Source: Internet
Author: User

C + + More emphasis on language practicality

1. All variables can be defined when they need to be used

I

int 0 ;  for (int i=1; i<=3; i++) {         for (int j=1; j<= 3; J + +)                  {+ = i * j;                }           }    

2. Register keyword request compiler to store local variables in registers

-register keyword is still supported in C + +

-c++ compiler has its own optimization method

Cannot get the address of register variable in C language

Address of register variable can be obtained in C + +

Register keyword in C + +

When the C + + compiler discovers that the address of a register variable is required in a program, the register of the variable becomes invalid.

The early C language compiler does not optimize the code, so the register variable is a good complement

3, in the C language, it is legal to repeatedly define a global variable with the same name, and more than one global variable with the same name in C will eventually be linked to the same address space on the global data area.

In C + +, it is not allowed to define multiple global variables with the same name

4, the strengthening of the struct keyword

-C language struct defines a set of variables

-a struct-defined identifier is not a new type in the C language

Structs in-c++ are used to define a completely new type

5. What is the difference between void F () and void f (void)?

The type of claim that all identifiers in C + + must display

The default type in C is not legal in C + +

In the C language:

int F () represents a function that returns a value of int that accepts arbitrary arguments

F (void) indicates an parameterless function with a return value of int

In C + +

int f () and int f (void) have the same meaning

An parameterless function that represents a return value of int

C-to-C + + upgrade

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.