C + + Enhancements

Source: Internet
Author: User

Usability "enhanced

Variables in the C language must be defined at the beginning of the scope!!

More emphasis is placed on the "practicality" of language in C + +, and all variables can be defined when they need to be used.

int main () {         inti = 0;         printf ("ddd");         INTK;         Return0;}

Register keyword Enhancements

Register keyword request compiler let the variable a directly in the register, fast speed in C language Register modified variable cannot take address, but in C + + can.

1

Change of register keyword

The Register keyword requests the compiler to store local variables in registers, and the register variable address cannot be obtained in the C language.

The Register keyword is still supported in C + +, and the C + + compiler has its own optimization method, which may be optimized without register, and C + + can get the address of the register variable.

2

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

3

The early C language compiler does not optimize the code, so the register variable is a good addition.
int main () {register int a = 0;printf ("&a =%x\n", &a); return 0;}

Function Detection Enhancements

In the C language, it is legal to repeatedly define multiple global variables with the same name.

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

Multiple global variables with the same name in C will eventually be linked to the same address space on the global data area.

int G_var;

int g_var = 1;

C + + directly rejects the practice of ambiguity.

struct type enhancement

The C-language struct defines a set of variables, which the C compiler does not consider to be a new type.

A struct in C + + is a new type of definition declaration.
struct student{    char name[10];    int age;}; int main (int argc, char *argv[]) {    Student S1 = {"Wan", 1};    Student s2 = {"Wan2", 2};        return 0;}

All variables and functions in C + + must have a type

The default type in the C language is not legal in C + +.

Summarize:

In the C language

int f (); Represents a function that takes an arbitrary argument with a return value of int.

int f (void); Indicates an argument function with a return value of int

In C + +

int f (), and int f (void) have the same meaning, all of which represent an parameterless function that returns a value of int

C + + More emphasis type, any program element must display the specified type


C + + Enhancements

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.