摘要: 一、代码 1 #include 2 using namespace std; 3 void main() 4 { 5 char a[10];//字符数组 6 cout>b[i];21 }22 int *q=b;23 cout<<q<<"="<<&b<<endl;//输出的是b的地址24 cout<<*q<<"="<<b[0]<<endl;//输出的b[0]25 cout<<&q<<endl;//输出的是指针q的地址 阅读全文
posted @ 2013-10-08 14:30 不懂编程的程序员 阅读(576) 评论(0) 推荐(0) 编辑
摘要: 一、异常处理简介 C++中,异常处理一般用3个保留字实现:throw、try和catch。当被调用的函数检测到异常条件时,立即使用throw引发一个异常。在上一层调用函数中使用try检测函数调用是否引发了异常,被检测到的异常由catch捕获并处理。二、try、catch语句 需要检测异常的程序段(如函数调用)须放在try语句中执行,称之为保护代码。异常由catch语句捕获并处理。形式为: 1 try 2 {...} 3 catch() 4 {...} 5 ... 6 ... 7 ... 8 catch() 9 {...}10 catch(...)11 {...} 一个try语句可与多个c... 阅读全文
posted @ 2013-10-07 17:01 不懂编程的程序员 阅读(307) 评论(0) 推荐(0) 编辑
摘要: 1、指针变量的声明: 数据类型 *指针变量名; int *p; //声明一个用于存储int型变量地址的指针变量p,即变量p是一个指向int类型的指针变量2、指针变量的初始化 数据类型标识符 *指针变量名=初始地址值; int i; //定义一个整型变量i,并为i分配内存空间 int *p=&i; //定义p为指针变量,并将i的地址赋值给指针变量p作为初值 特例:指向字符类型的指针变量可以对字符串进行初始化 char *str="Hello World"; //将字符串的第0个字符'H'的地址赋给指针变量str3、一个程序:1 void main()2 阅读全文
posted @ 2013-09-27 10:51 不懂编程的程序员 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 一、代码 1 //输出字符数组奇数位的数,要求使用指针实现 2 #include 3 void main() 4 { 5 int n; 6 cout>n; 8 char *a=new char [n]; 9 for (int i=0;i>a[i];12 }13 char *p=a;14 for(int j=0;j<n;j++)15 if(j%2==0)16 {17 cout<<p[j]<<" ";18 j++;19 }20 delet... 阅读全文
posted @ 2013-09-25 21:41 不懂编程的程序员 阅读(292) 评论(0) 推荐(0) 编辑
摘要: 一、代码 1 /////////////////// 2 /*动态分配数组 3 int *p=new int[size]; 4 .... 5 delete[]p; 6 */ 7 //////用动态数组求斐波那契的前N项 8 #include 9 using namespace std;10 void main()11 {12 int n;13 cout>n;15 cout<<"前"<<n<<"项为:"<<endl;16 int *p=new int[n];//动态生成数组17 if (p==0||p& 阅读全文
posted @ 2013-09-25 15:43 不懂编程的程序员 阅读(517) 评论(0) 推荐(0) 编辑
摘要: 一、代码 1 #include 2 using namespace std; 3 void swap1(int x,int y) 4 { 5 int t=x; 6 x=y; 7 y=t; 8 cout>a>>b;23 cout<<"a和b交换前的值为:a="<<a<<" b="<<b<<endl;24 swap1(a,b);25 swap2(&a,&b);26 cout<<"a和b交换后的值为:a="<<a<&l 阅读全文
posted @ 2013-09-25 15:13 不懂编程的程序员 阅读(1000) 评论(0) 推荐(0) 编辑
摘要: 一、代码 1 //将字符串中的小写字母转换为大写 2 #include 3 using namespace std; 4 //转换函数 5 char *fun(char *str) 6 { 7 int i=0; 8 int m=strlen(str); 9 cout='a'&&str[i]>a;26 fun(a);27 cout='a'&&str[i]='a'&&str[i]<='z')结果演示: 阅读全文
posted @ 2013-09-20 15:39 不懂编程的程序员 阅读(1075) 评论(0) 推荐(0) 编辑
摘要: 一、代码 1 #include 2 using namespace std; 3 //求整形数组中最大的元素 4 int imax(int array[],int count) 5 { 6 int temp=array[0]; 7 for (int i=0;i=array[i])23 temp=array[i];24 }25 cout>MaxSize;34 int *Array=new int[MaxSize];35 cout>Array[i];39 } 40 imax(Array,MaxSize);41... 阅读全文
posted @ 2013-09-18 21:15 不懂编程的程序员 阅读(369) 评论(0) 推荐(0) 编辑
摘要: 一、代码 1 //字符串反转 2 #include 3 using namespace std; 4 void mystrrev(char string[]) 5 { 6 int len=strlen(string);//判断字符串长度 7 cout=0;i--) 9 {10 cout>a;19 mystrrev(a);20 }二、演示 阅读全文
posted @ 2013-09-18 15:40 不懂编程的程序员 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 一、代码 1 //在输入的字符串中查找特定字符,查到返回位置和个数 2 #include 3 using namespace std; 4 int mystrchr(char string[],char c) 5 { 6 int len=strlen(string);//判断字符串长度 7 int count=0;//记录c的个数 8 cout>a;25 cout>m;28 mystrchr(a,m);29 }二、演示 阅读全文
posted @ 2013-09-18 15:32 不懂编程的程序员 阅读(848) 评论(0) 推荐(0) 编辑