上一页 1 ··· 5 6 7 8 9 10 11 下一页
摘要: 在C++中,基于以下如下我们通过以引用reference的形式传递变量。 (1)To modify local variables of the caller function A reference(or pointer) allows called function to modify a local variable of the caller function. For example, consider te following example program where fun() is able to modify local variable x of main().... 阅读全文
posted @ 2013-11-25 21:57 虔诚的学习者 阅读(421) 评论(0) 推荐(0) 编辑
摘要: 在C++中,引用比指针更加的安全,一方面是因为引用咋定义时必须进行初始化,另一方面是引用一旦被初始化就无法使其与其他对象相关联。 但是,在使用引用的地方仍然会有一些例外。 (1)Reference to value at uninitialized pointer1 int *ptr;2 int &ref = *ptr; //Reference to value at some random memory location (2)Reference to a local variable is returned 1 int& fun()2 {3 int a = 10;4... 阅读全文
posted @ 2013-11-25 21:29 虔诚的学习者 阅读(253) 评论(0) 推荐(0) 编辑
摘要: When a variable is declared as reference, it becomes an alternative name for an existing variable. A variable can be declared as reference by putting ‘&’ in the declaration. 1 #include 2 using namespace std; 3 4 int main() 5 { 6 int x = 10; 7 8 // ref is a reference to x. 9 int& ref = x;... 阅读全文
posted @ 2013-11-25 21:06 虔诚的学习者 阅读(299) 评论(0) 推荐(0) 编辑
摘要: Predict the output of the following program? 1 #include 2 using namespace std; 3 4 class Empty 5 { 6 }; 7 8 int main() 9 {10 cout 2 using namespace std; 3 4 class Empty 5 { 6 }; 7 8 int main() 9 {10 Empty a, b;11 12 if (&a == &b)13 {14 cout 2 using namespace std... 阅读全文
posted @ 2013-11-25 20:39 虔诚的学习者 阅读(300) 评论(0) 推荐(0) 编辑
摘要: A class declaration can contain static object of self type,it can also have pointer to self type,but it can not have a non-static object of self type。 例如,下面的程序可运行。 1 // A class can have a static member of self type 2 #include 3 4 using namespace std; 5 6 class Test 7 { 8 static Test self; ... 阅读全文
posted @ 2013-11-25 20:15 虔诚的学习者 阅读(309) 评论(0) 推荐(0) 编辑
摘要: 在C++中,除了以下几点外,struct和class是相同的。 (1)class的成员的默认访问控制是private,而struct的成员的默认访问权限是public。 例如,program 1会编译失败,而program 2可正常运行。 1 // Program 1 2 #include 3 4 class Test 5 { 6 int x; // x is private 7 }; 8 9 int main()10 {11 Test t;12 t.x = 20; // compiler error because x is private13 getc... 阅读全文
posted @ 2013-11-25 19:53 虔诚的学习者 阅读(431) 评论(0) 推荐(0) 编辑
摘要: C++语言1.1.全局变量和局部变量在内存中是否有区别?如果有,是什么区别?解析: 1)预备知识——程序的内存分配 一个由C/C++编译的程序占用的内存分为以下几个部分: (1)栈区(stack)——由编译器自动分配、自动释放,比如存放函数的参数值、局部变量的值等。其操作方式类似于数据结构中的栈。 (2)堆区(heap)——一般由程序员分配释放,若程序员不释放,程序结束时可能由操作系统回收。分配方式类似于链表。 (3)全局静态区——全局变量和静态变量的存储是放在一块的,初始化的全局变量和静态变量在一块区域(.data),未初始化的全局变量和未初始化的静态变量在相邻的另一块区域(.bs... 阅读全文
posted @ 2013-11-25 18:27 虔诚的学习者 阅读(283) 评论(0) 推荐(0) 编辑
摘要: 上面来自网友,谢谢。 转载请注明:http://www.cnblogs.com/iloveyouforever/ 阅读全文
posted @ 2013-11-18 20:52 虔诚的学习者 阅读(198) 评论(0) 推荐(0) 编辑
摘要: 1、给一个单词a,如果通过交换单词中字母的顺序可以得到另外的单词b,那么b是a的兄弟单词,比如的单词army和mary互为兄弟单词。解析: 现在要给出一种解决方案,对于用户输入的单词,根据给定的字典找出输入单词有哪些兄弟单词。请具体说明数据结构和查询流程,要求时间和空间效率尽可能地高。 字典树的典型应用,一般情况下,字典树的结构都是采用26叉树进行组织的,每个节点对应一个字母,查找的时候,就是一个字母一个字母的进行匹配,算法的时间复杂度就是单词的长度n,效率很高。因此这个题目可以定义一个字典树作为数据结构来查询的,时间效率会很高,这样就转化为在一棵字典树中查找兄弟单词,只要在字典树中的前缀.. 阅读全文
posted @ 2013-11-18 20:26 虔诚的学习者 阅读(329) 评论(0) 推荐(0) 编辑
摘要: 1、extern“C”是什么含义?用来解决什么问题?分析: extern“C”包含双重含义,从字面上即可得到:首先,被它修饰的目标是”extern”的;其次,被它修饰的目标是”C”的。让我们来详细解读这两重含义。 extern“C”是指将该段代码以C语言形式进行编译、链接。由于C不支持函数重载,C与C++对于同一个函数编译后在符号表中保存的函数名字存在差异,故当进行C、C++混合编程时会出现一些问题。 用来解决C与C++程序连接问题,extern“C”实现C和C++的混合编程。2、写出至少两种设计模式,阐明其使用场景,有伪代码更好。分析: 单例模式、适配器模式、工场模式、装饰模式等23... 阅读全文
posted @ 2013-11-18 20:12 虔诚的学习者 阅读(396) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 下一页