 |
我的日历 |
|
|
分类日志 |
|
|
友情链接 |
|
|
最新评论 |
|
|
搜索日志 |
|
|
访问计数 |
|
|
获取 RSS |
| |
 | |
|
array and pointer [2005-4-18] youalwayscan 发表在 C/C+基础
| Given the definitions int a[10][20]; int *b[10];
The important advantage of the pointer array is that the rows of the array may be of different lengths. That is, each element of b need not point to a twenty-element vector; some may point to two elements, some to fifty, and some to none at all.
By far the most frequent use of arrays of pointers is to store character strings of diverse lengths. Compare the declaration and picture for an array of pointers: char *name[] = { "Illegal month", "Jan", "Feb", "Mar" }; (not 15*k bytes)
with those for a two-dimensional array:
char aname[][15] = { "Illegal month", "Jan", "Feb", "Mar" };(45 Bytes)
| |
|
|