c++基础知识03
1.嵌套循环案例——九九乘法表
int main() { //利用嵌套循环乘法口诀表 for (int n = 1; n <= 9; n++) { for (int m = 1; m <= n ; m++) { cout << m << "*" << n << "=" << m * n<<" "; //即使是单字符也要使用双引号切记!! } cout << endl; } system("pause"); return 0;
2.跳转语句
1)总共有三类:break、continue和 goto。
2)其中break和continue的用法与其他编程语言相似。
3)goto语句需特别说明一下:代码运行时会强行跳转到标记处;
goto 标记名称(一般大写字母);
标记名称:
3.一维数组
定义:1)数据类型 数组名[数组长度];
2)数据类型 数组名[数组长度]={,,};
3)数据类型 数组名[]={,,,};
数组名用途:
1)统计整个数组内存长度: sizeof(数组名)
单个数组元素内存长度:sizeof(数组名[0])
数组长度:整个数组内存长度/单个数组元素内存长度:sizeof(arr)/sizeof(arr[0])
2)数组内存首地址: cout<<(int)arr<
数组元素逆置
int a[] = {1,4,5,3,6,7}; int b = sizeof(a) / sizeof(a[0]);//数组长度 cout << "数组逆置前:" << endl; for (int i = 0; i < b; i++) { cout << a[i] << endl; } int start = 0;//数组起始位置 int end = b-1;//数组末尾位置 for ( ; start < end;) { //元素互换 int temp = a[start]; a[start] = a[end]; a[end] = temp; start++; end--; } cout << "数组逆置后:" << endl; for (int i = 0; i < b; i++) { cout << a[i] << endl; }TRANSLATE with
Arabic | Hebrew | Polish |
Bulgarian | Hindi | Portuguese |
Catalan | Hmong Daw | Romanian |
Chinese Simplified | Hungarian | Russian |
Chinese Traditional | Indonesian | Slovak |
Czech | Italian | Slovenian |
Danish | Japanese | Spanish |
Dutch | Klingon | Swedish |
English | Korean | Thai |
Estonian | Latvian | Turkish |
Finnish | Lithuanian | Ukrainian |
French | Malay | Urdu |
German | Maltese | Vietnamese |
Greek | Norwegian | Welsh |
Haitian Creole | Persian |