C + + Primer Quick Start VI: arrays and pointers

Source: Internet
Author: User

Update: Errata, delete [] pig

We know that the C language, as well as the early structure-oriented language, almost all support array definitions, such as the shaped array int goddess [2], which indicates two numbers: Goddess [0], goddess [1], they are all integers. This is supported by the C + + language for efficiency and compatibility reasons. Of course, after all, it is the children of Others (standard) that do not offer those magical abilities similar to those of vector and iterator types. The difference from vector is that the length of the array is fixed. In addition, the pointer is still the pointer, no change.

?
When we program, we try to use vectors to avoid using arrays and pointers. With the vector and her iterator, as well as the many template functions she brings, we are programmed to be much more convenient than C.

Array usage Examples:
The dimensions of the array are first specified, and must be specified within a pair of brackets []:

12 Char girl[128] = {Ten, 30};int boy[] = {7, 8, 9};

Use of pointers:

Each pointer has a data type associated with it, which determines the type of object that the pointer points to. For example, an int type pointer can only point to an int type object.

1234567891011 int * Goddess 1, * Goddess 2;             Goddesses all point to shaping int int Goddess 3; double * male god;         The male god points to the variable of the double type int *sp = Goddess 3;  SP is the address of the goddess 3 int * pig = new INT[10]; The pig pointer points to a 10-shaped array of values delete [] pig;

What do you think? is quite simple, actually arrays and pointers are very simple, but not to play a role in the Nexus, I really do not want to write her.

This article is original, reproduced please indicate the source, offenders must investigate

Focus on the public platform: the Programmer Interaction Alliance (coder_online), you can get the first original technical articles, and (Java/c/c++/android/windows/linux) technology Daniel Friends, online communication programming experience, get programming basics, Solve programming problems. Programmer Interactive Alliance, Developer's own home.

C + + Primer Quick Start VI: arrays and pointers

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.