c++
文章平均质量分 73
a382004737
这个作者很懒,什么都没留下…
展开
-
指针1
#include <iostream> using namespace std; void change(int x,int *pm) { x = 10; *pm = 10; } void swap(int* p1,int* p2) { //p1和p2都是形参,函数结束完了就没有了 int* temp; temp = p1; p1= p2...原创 2013-07-28 22:38:02 · 78 阅读 · 0 评论 -
预编译
#include <iostream> using namespace std; //宏定义 没'='号 无需';'号 #define MAXNUM 10 //带参数的宏定义 #define CUBE(x) (x*x*x) //条件编译 //#if 如果 //#elif 如果 //#endif 结束编译 //#ifdef 如果标示符有定义 //#if...原创 2013-07-31 22:05:55 · 69 阅读 · 0 评论 -
动态内存分配
#include <iostream> using namespace std; void mian() { char* pc; int* pi; //new 类型标示符 pc =new char; *pc = 'a'; cout<<*pc<<endl; //new 类型标示符(初始值) pi = new int(8);...原创 2013-07-31 23:52:48 · 72 阅读 · 0 评论 -
自定义数据类型
定义和使用结构.cpp #include <iostream> #include <string> using namespace std; struct Student { int nID; char szName[20]; char szAddr[100]; char szPhone[15]; float fScore; }...原创 2013-08-07 00:13:48 · 137 阅读 · 0 评论 -
const总结一
关于指针const 情况一: int i = 10; const int* p = &i; *p = 10 ; //error C3892: “p”: 不能给常量赋值 情况二: int i = 10; int* const p = &i; p++; //error C3892: “p”: 不能给常量赋值 总结:编译器会提示报错。原因是 con...原创 2013-09-22 18:20:19 · 102 阅读 · 0 评论 -
const总结二 之 常量函数形参
总结:常量函数形参传递参数,保证参数在函数体里面不受修改。有时候,如果形参是指针形参或者引用形参,或者是字符数组,不想函数体对其进行修改,那么可以采用常量函数形参。 实例: 定义EObject类,该类有width和height两个属性,有4个函数对其进行读取和修改。 class EObject { public: EObject(void); ~EObject(void); ...原创 2013-09-22 21:20:33 · 236 阅读 · 0 评论 -
const总结三 之 常量函数返回值
先贴代码: class Return { public: Return(void); ~Return(void); const int getInt(); const int* getIntPointL(); int* const getIntPointR(); }; #include "Return.h" Return::Return...原创 2013-09-22 22:07:16 · 325 阅读 · 0 评论