C++, Array

0. 

1. Array

Its size is fixed;

The size must be known at compile-time;

2. Examples   

const unsigned buf_size = 512;

int ia[buf_size];    // an empty array, the length is determined

int ia[] = {0,1,2};  // ok, initialize an array without explicitly saying the length 

int* paArr[buf_size];   // paArr is an array of pointers

int* pa = new int(100); // pa is a pointer to a dynamically allocated array

delete[] pa;        // no memory leak

delete pa;         // memory leak

char ca[] = {'h','e','l','l','o'}; // sizeof(ca) is 5

char ch[20] = {'a'};         // sizeof(ch) is 20

char chs[] = {"hello"};       // sizeof(chs) is 6, not 5

string str("hello woruld");      // s is a string, the string is a class

string *p = &str; 

原文地址:https://www.cnblogs.com/sarah-zhang/p/12293754.html