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