上一页 1 ··· 79 80 81 82 83 84 85 86 87 ··· 95 下一页
摘要: 数组要么在静态存储区被创建(如全局数组),要么在栈上被创建。指针可以随时指向任意类型的内存块。(1)修改内容上的差别char a[] = “hello”;a[0] = ‘X’;char *p = “world”; // 注意p 指向常量字符串p[0] = ‘X’; // 编译器不能发现该错误,运行时错误(2) 用运算符sizeof 可以计算出数组的容量(字节数)。sizeof(p),p 为指针得到的是一个指针变量的字节数,而不是p 所指的内存容量。C++/C 语言没有办法知道指针所指的内存容量,除非在申请内存时记住它。注意当数组作为函数的参数进行传递时,该数组自动退化为同类型的指针。char 阅读全文
posted @ 2012-06-27 19:42 byfei 阅读(142) 评论(0) 推荐(0) 编辑
摘要: class String{public:String(const char *str ); // 通用构造函数String(const String &another); // 拷贝构造函数~ String(); // 析构函数String & operater =(const String &rhs); // 赋值函数private:char *m_data; // 用于保存字符串};尝试写出类的成员函数实现。答案:String::String(const char *str){if ( str == NULL ) //strlen在参数为NULL时会抛异常才会有这步 阅读全文
posted @ 2012-06-27 19:27 byfei 阅读(83) 评论(0) 推荐(0) 编辑
摘要: 1. 结构和联合都是由多个不同的数据类型成员组成, 但在任何同一时刻, 联合中只存放了一个被选中的成员(所有成员共用一块地址空间), 而结构的所有成员都存在(不同成员的存放地址不同)。2. 对于联合的不同成员赋值, 将会对其它成员重写, 原来成员的值就不存在了, 而对于结构的不同成员赋值是互不影响的。 阅读全文
posted @ 2012-06-27 19:22 byfei 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 引用是除指针外另一个可以产生多态效果的手段。这意味着,一个基类的引用可以指向它的派生类实例。例4Class A; Class B : Class A{...}; B b; A& ref = b; 阅读全文
posted @ 2012-06-27 19:19 byfei 阅读(233) 评论(0) 推荐(0) 编辑
摘要: int a ;const int &ra=a;ra=1; //错误a=1; //正确例2string foo( );void bar(string & s);那么下面的表达式将是非法的:bar(foo( ));bar("hello world");原因在于foo( )和"hello world"串都会产生一个临时对象,而在C++中,这些临时对象都是const类型的。因此上面的表达式就是试图将一个const类型的对象转换为非const类型,这是非法的。引用型参数应该在能被定义为const的情况下,尽量定义为const 。 阅读全文
posted @ 2012-06-27 19:14 byfei 阅读(127) 评论(0) 推荐(0) 编辑
摘要: int func(x){int countx = 0;while(x){countx ++;x = x&(x-1);}return countx;} 假定x = 9999。 答案:8 阅读全文
posted @ 2012-06-27 19:09 byfei 阅读(155) 评论(0) 推荐(0) 编辑
摘要: Node * MergeRecursive(Node *head1 , Node *head2){if ( head1 == NULL )return head2 ;if ( head2 == NULL)return head1 ;Node *head = NULL ;if ( head1->data < head2->data ){head = head1 ;head->next = MergeRecursive(head1->next,head2);}else{head = head2 ;head->next = MergeRecursive(head1 阅读全文
posted @ 2012-06-27 19:02 byfei 阅读(795) 评论(0) 推荐(0) 编辑
摘要: Node * Merge(Node *head1 , Node *head2){if ( head1 == NULL)return head2 ;if ( head2 == NULL)return head1 ;Node *head = NULL ;Node *p1 = NULL;Node *p2 = NULL;if ( head1->data < head2->data ){head = head1 ;p1 = head1->next;p2 = head2 ;}else{head = head2 ;p2 = head2->next ;p1 = head1 ;}N 阅读全文
posted @ 2012-06-27 18:59 byfei 阅读(474) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std;struct Node{ int nData; Node * pNext;};Node *CreateList(Node* pHead){ Node * pTemp; for(int i = 1;i<10;i++) { pTemp = new Node(); pTemp->nData = i; pTemp->pNext = pHead; pHead = pTemp; } return pHead;}Node *ReverseList(Node* pHead){ Node* p1 = pH 阅读全文
posted @ 2012-06-27 18:55 byfei 阅读(130) 评论(0) 推荐(0) 编辑
摘要: typedef map<int, int> templatemap;templatemap AllScoreSort; for(int i=10000;i<10010;i++) AllScoreSort[i]=i+1; for (templatemap::iterator iter = AllScoreSort.begin(); iter!= AllScoreSort.end(); iter++){int nRoleID = iter->first;int nScore = iter->second;if (10005 < nRoleID){//AllSco 阅读全文
posted @ 2012-06-21 16:42 byfei 阅读(180) 评论(0) 推荐(0) 编辑
上一页 1 ··· 79 80 81 82 83 84 85 86 87 ··· 95 下一页