没有合适的资源?快使用搜索试试~ 我知道了~
本人在加州大学计算机系的C++教材,前后大概会有30篇,包括讲义,作业等等。非常易懂。
资源详情
资源评论
资源推荐
Dr. Ahmad R. Hadaegh
A.R. Hadaegh California State University San Marcos (CSUSM) Page
1
One Dimensional Arrays:
Structured data types
Review
The contents of this particular lecture prepared by the instructors at the
University of Manitoba in Canada and modified by Dr. Ahmad Reza Hadaegh
Dr. Ahmad R. Hadaegh
A.R. Hadaegh California State University San Marcos (CSUSM) Page
2
One Dimensional Arrays
- Key observation:
- arrays can be indexed with variables
int main() {
char line[ 80];
int i;
for (i= 0; i< 80; i= i+ 1)
cin >> line[ i];
for( i= 0; i< 80; i= i+ 1)
cout << line[ i];
for( i= 79; i>= 0; i= i- 1)
cout << line[ i];
}
Loop runs
i= 0, i= 1, i= 2, ..., i= 79
Dr. Ahmad R. Hadaegh
A.R. Hadaegh California State University San Marcos (CSUSM) Page
3
One Dimensional Arrays
- Arrays can be declared of any data type
- char, int, float, .…
- General format of array declaration:
DataType ArrayName [ConstIntExpression];
- DataType is the data type of the array elements
- ArrayName is the name of the array
- ConstIntExpression is a literal int or int constant
Dr. Ahmad R. Hadaegh
A.R. Hadaegh California State University San Marcos (CSUSM) Page
4
One Dimensional Arrays
- Examples of Array Declaration
- float cmplx[2]; // entries: cmplx[0], cmplx[1]
- int ivec[2000]; // entries: ivec[0], ..., ivec[1999]
- const int arraylen= 1000;
- char biglin[arraylen];
// array biglin has entries biglin[0],..., biglin[999];
Dr. Ahmad R. Hadaegh
A.R. Hadaegh California State University San Marcos (CSUSM) Page
5
One Dimensional Arrays
- Accessing Array Components
- General form of array access is:
ArrayName[IndexExpression]
- ArrayName is the name of the array
- IndexExpression is any integer expression
- When evaluated, an array access is just like any other
accessed variable
- treat it like you would any value of the array type
剩余48页未读,继续阅读
zhuxiangan
- 粉丝: 1
- 资源: 22
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0