指针,数组和串

1.Pointers
Each program variable is stored in the computer's memory at some location, or address.
A pointer is a variable that holds the value of such an address.
For example:
Given a type T, the type T* denotes a pointer to a variable of type T.


Two essential operators are used ti manipulate pointers.
The first returns the address of an object in memory,
and the second returns the contents of a given address.


2.Arrays
An arrays is a collection of elements of same type.
Given any type T and a constant N, a variable of type T[N] holds an array of N elements,
each of type T.Each element of the array is referenced by its index, that is, a number
from 0 to N-1.


3.Pointers and Arrays
The name of an array is equivalent to a pointer to the array's initial element and vice versa.
for example:
char c[] = {'c', 'a', 't'};
char* p = c; // p points to c[0]
char* q = &c[0]; // q also points to c[0]
cout << c[2] << p[2] << q[2]; // outputs "ttt"


4. Strings
A string literal such as "Hello, World", is represented as a fixed-length array of characters
that ends with the null character. Character strings represented in this way are called C-stype
strings. since they are inherited from C, unfortunately, this representation alone does not
provide many string operations, such as concatenation and comparison. It also possesses all the
peculiarities of C++ arrays, as mentioned earlier.
For this reason, C++ provides a string type as part of its Standard Template Library(STL). When
we need to distinguish, we call these STL strings. In order to use STL strings it is necessary
to include the header file <string>.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值