do break的妙用
摘要:#include #include int func(int n){ //资源的统一申请 int i = 0; int ret = 0; int* p = (int*)malloc(sizeof(int) * n); do { if( NULL ...
阅读全文
posted @
2015-07-20 22:32
思齐_
阅读(459)
推荐(0) 编辑
交换两个变量的不同实现方式
摘要:#include #define SWAP1(a,b) \{ \ int temp = a; \ a = b; \ b = temp; \}#define SWAP2(a,b) \{ \...
阅读全文
posted @
2015-07-19 16:25
思齐_
阅读(354)
推荐(0) 编辑
C语言柔性数组
摘要:柔性数组:数组大小待定的数组。C语言中结构体最后一个元素可以是大小未知的数组。C语言可以由结构体产生柔性数组柔性数组的结构如何只能堆上生成柔性数组是C99的扩展,简而言之就是一个在struct结构里的标识占位符(不占结构struct的空间)。#include #include typedef str...
阅读全文
posted @
2015-07-19 11:14
思齐_
阅读(1862)
推荐(0) 编辑
字节对齐
摘要:为什么需要字节对齐?计算机组成原理教导我们这样有助于加快计算机的取数速度,否则就得多花指令周期了。为此,编译器默认会对结构体进行处理(实际上其它地方的数据变量也是如此),让宽度为2的基本数据类型(short等)都位于能被2整除的地址上,让宽度为4的基本数据类型(int等)都位于能被4整除的地址上,以...
阅读全文
posted @
2015-07-18 23:23
思齐_
阅读(845)
推荐(0) 编辑
C语言sizeof
摘要:一、关于sizeof1.它是C的关键字、是一个运算符,不是函数;2.一般用法为sizeof 变量或sizeof(数据类型);后边这种写法会让人误认为是函数,但这种写法是为了防止和C中类型修饰符(static、const、extern等)冲突。二、demo1.源码test.c#include int ...
阅读全文
posted @
2015-07-16 23:43
思齐_
阅读(449)
推荐(0) 编辑
c++学习-特殊类成员
摘要:静态变量:#include#include#include using namespace std;class A{public: A(){ total++; } static int total;};//@warn 静态成员变量必须在全局进行定义int A::total =...
阅读全文
posted @
2015-07-12 17:48
思齐_
阅读(393)
推荐(0) 编辑
c++学习-多态性
摘要:强制转换父类对象为子类#include#include#include using namespace std;class father{public: void smart(){} virtual ~father(){}};class son : public father{pub...
阅读全文
posted @
2015-07-04 22:34
思齐_
阅读(282)
推荐(0) 编辑
c++学习-链表
摘要:静态链表:#include#includeusing namespace std;struct book{ int num; float price; struct book *next;};int main(){ book x, y, z, *head, *p; x ...
阅读全文
posted @
2015-06-28 12:55
思齐_
阅读(250)
推荐(0) 编辑
c++学习-字符串
摘要:字符数组和 string类型比较的区别#include#includeusing namespace std;class area{public: area(){ cout i = i; cout w = w; this->h = h; cout w = w; this->h =...
阅读全文
posted @
2015-06-27 14:57
思齐_
阅读(470)
推荐(0) 编辑
c++学习-数组
摘要:int a[10]; //是个元素,在windows下回报错,linux会输出一个随机数int a[10]={1,2}; //初始化,其他的为0数组越界:为了调高效率, 编译器不会对数组越界做检查#include using namespace std;int main(){ int ...
阅读全文
posted @
2015-06-21 23:07
思齐_
阅读(462)
推荐(0) 编辑
c++学习-虚函数
摘要:#include using namespace std;class common{public: virtual void hello(){couthello(); return 0;}静态联编:在编译时就确定指针指向的类#include using namespace std;cla...
阅读全文
posted @
2015-06-21 15:21
思齐_
阅读(224)
推荐(0) 编辑
c++学习-继承
摘要:继承#include using namespace std;class father{public: void getHeight(){coutweightheightageusing namespace std;class father{public: int height;};cl...
阅读全文
posted @
2015-06-21 12:32
思齐_
阅读(225)
推荐(0) 编辑
c++学习-运算符重载
摘要:重载=号运算符,由于成员属性中有指针会出现错误#include using namespace std;class num{public: num(){n=new int;*n=1;coutx=a.x;cout two.operator =(one); coutusing nam...
阅读全文
posted @
2015-06-20 23:02
思齐_
阅读(275)
推荐(0) 编辑
c++学习
摘要:#includeint main(){ std::cout>sjk; std::cout//using std::cout;//using std::endl;using namespace std;int main(){ cout//using namespace std;nam...
阅读全文
posted @
2015-06-13 23:50
思齐_
阅读(720)
推荐(0) 编辑