}
上述程序运行时,如果输入数据10 20并回车后,则输出结果为20 10。
由【例2】可看出:
(1)传递引用给函数与传递指针的效果是一样的。这时,被调函数的形参就成为原来主调
函数中的实参变量或对象的一个别名来使用,所以在被调函数中对形参变量的操作就是对其相应的目标对象(在主调函数中)的操作。
(2)使用引用传递函数的参数,在内存中并没有产生实参的副本,它是直接对实参操作;而使用一般变量传递函数的参数,当发生函数调用时,需要给形参分配存储单元,形参变量是实参变量的副本;如果传递的是对象,还将调用拷贝构造函数。因此,当参数传递的数据较大时,用引用比用一般变量传递参数的效率和所占空间都好。
(3)使用指针作为函数的参数虽然也能达到与使用引用的效果,但是,在被调函数中同样要给形参分配存储单元,且需要重复使用"*指针变量名"的形式进行运算,这很容易产生错误且程序的阅读性较差;另一方面,在主调函数的调用点处,必须用变量的地址作为实参。而引用更容易使用,更清晰。
如果既要利用引用提高程序的效率,又要保护传递给函数的数据不在函数中被改变,就应使用常引用。
自己理解的:::引用就好象取了另一个名字,比如我现在叫小明,取个外号叫猪头,但是所指的是同一个人而已
我是如此理解的,我们应该知道皮影戏,人用线操做木偶,我们可以这个样子想,比如我们可以用手操作木偶去办事,木偶做的事不就是自己直接在做的啊,所以在子函数中操作就等于在主函数中操作一样(我自己理解的可能有错误)
但是我们可能碰到例如
intStackEmpty(SqStack s)
{
if(s.top == s.base)
return TRUE;
return FALSE;
}
int Push(SqStack&s, SElemType e)
{
if(s.top - s.top>= s.stacksize) {
s.base = (SElemType *)realloc(s.base,
(s.stacksize + STACKINCREMENT) * sizeof(SElemType));
if(!s.base)
exit(OVERFLOW);
s.top = s.base + s.stacksize;
s.stacksize += STACKINCREMENT;
}
*s.top++ = e;
return TRUE;
}
int Pop(SqStack&s, SElemType&e)
{
if(s.top == s.base)
return FALSE;
e = *--s.top;
return TRUE;
}
在堆栈操作中,有的不用&,有的要用&,为什么呢?
3.4 什么时候使用引用
转()
现在可以总结一下什么时候使用引用这个问题了。首先我们要看看什么时候必须使用引用:
流操作符<<和>>、赋值操作符=的返回值
拷贝构造函数的参数、赋值操作符=的参数
其它下面的情况都是推荐使用引用,但是也可以不使用引用。如果不想使用引用,完全可以使用指针或者其它类似的东西替代:
异常catch的参数表
大对象作为参数传递
返回容器类中的单个元素
返回类数据成员(非内建数据类型成员)
返回其它持久存在的,且获得者不负责销毁的对象
另外一些情况下,不能返回引用:+-*/四则运算符
疑问代词用法总结及练习
疑问代词用法总结及练习 句子是英语学习的核心。从句子使用的目的来分,它可分为四类 1、陈述句(肯定句和否定句) 2、疑问句(一般疑问句、特殊疑问句和选择疑问句) 3、祈使句(肯定句和否定句) 4、感叹句。 四大句子类型的相互转换,对于学生来讲是个难点,为此,可通过说顺口溜的形式来帮助学生解决这一难题。 如:将陈述句变成一般疑问句,可以变成这样的顺口留:疑问疑问调个头,把be(系动词“is are am”)放在最前头。 如:将陈述句的肯定句变成否定句,我们就可以这样说:否定,否定加“not”,加在何处,加在系动词的后面。 在句子相互转换的题型中,最难的要算“就下列划线部分提问”或是“看答句,写问句”这种题型了,其实,我们只要熟练掌握疑问词(what,what time, what colour, where, when, who, whose, which, how, how old ,how tall, how long, how big, how heavy , how much, how many等等)具体用法。
习题 一、选择正确的单词填空 (who, where, when) is that pretty girl She is my sister. are Jack and Tom They are behind you. do you go to school I go to school from Monday to Friday. has a beautiful flower John has a beautiful flower.
are they They are my parents. is my mother She is in the living room. are you going We are going to the bakery(面包坊). Jim and Wendy play ball They play ball in the afternoon. does he jog He jogs in the park. are you from I'm from Changchun city. 11. _______ is your birthday –On May 2nd. 12、_______ are you --- I`m in the office. 13. are you ---- I`m Alice. 二.用(what time, what color, what day, what)填空。 1. A: ______ _______ is it B: It is nine o’clock. 2. A: ______ _______ does your mother get up B: My mother gets up at 6:30. 3. A: ______ _______ do you go to bed B: I go to bed at 10:00. 4. A: ______ _______ do Diana and Fiona have supper B: Diana and Fiona have supper at 18:00. 5. A: ______ _______is it B: It is purple. 6. A: ______ _______ is the sky B: The sky is blue. 7. A: ______ _______ is your coat B: My coat is black. 8. A: ______ _______ is the dog B: The dog is white. 9. A: ______ _______ is today B: Today is Monday. 10. A: ______ _______ is tomorrow B: Tomorrow is Tuesday. 11. A: ______ _______ was yesterday B: Yesterday was Sunday. 12. A: ______ _______ do you like B: I like red. 13. A: ______ is this This is a computer. 14. A: ______ are you doing B: We are playing basketball.
const int
const int* a = &b 和const* int a = &b的区别收藏 如果const关键字不涉及到指针,我们很好理解,下面是涉及到指针的情况: int b = 500; const int* a = &b; [1] int const *a = &b; [2] int* const a = &b; [3] const int* const a = &b; [4] 如果你能区分出上述四种情况,那么,恭喜你,你已经迈出了可喜的一步。不知道,也没关系,我们可以参考《Effective c++》Item21上的做法,如果const位于星号的左侧,则const就是用来修饰指针所指向的变量,即指针指向为常量;如果const位于星号的右侧,const就是修饰指针本身,即指针本身是常量。因此,[1]和[2]的情况相同,都是指针所指向的内容为常量(const放在变量声明符的位置无关),这种情况下不允许对内容进行更改操作,如不能*a = 3 ;[3]为指针本身是常量,而指针所指向的内容不是常量,这种情况下不能对指针本身进行更改操作,如a++是错误的;[4]为指针本身和指向的内容均为常量。另外const 的一些强大的功能在于它在函数声明中的应用。在一个函数声明中,const 可以修饰函数的返回值,或某个参数;对于成员函数,还可以修饰是整个函数。有如下几种情况,以下会逐渐的说明用法: A& operator=(const A& a); void fun0(const A* a ); void fun1( ) const; // fun1( ) 为类成员函数 const A fun2( ); --------------------------------------------------------------------------------------------------------------------------------------------- const int * pi 、int const * pi与int * const pi及其操作 (本贴已经做了重大修改) 1 从const int i 说起
Make短语总结
Make短语总结 1.make good use of/make full use of 2.Both husband and wife had to work to make ends meet.使收支平衡。 3.After years as an unsuccessful businessman, he finally made it.成功 4.What a strange person she is!I can’t make her out at all.理解,明白 5.The explanation in the schoolbook makes no sense, because the words are hard.讲不通,没意义,不能被理解 6.The teacher asked the children to make up a story about a trip to the moon.编造 7.The actors were making up when we arrived.打扮 8.Mary had to make up for the time she missed in school when she was sick, by studying very hard.弥补 9.The team is made up of nine players.由。。组成 10.He’ll make a good lawyer.有条件成为 11.The large print makes for easier reading.有助于,有利于 12.People in the West make it a rule to buy Christmas presents for their relatives and friends. 13.The teacher raised his voice so that he could make himself heard. 14.“Make yourself at home,”the hostess said to me as soon as I entered the house.别拘束,随便 Exercises: 1.(2012年陕西卷13题)No matter where he is , he makes_____ a rule
英语一般疑问句用法总结
英语一般疑问句用法总结 1. 基本用法及结构 一般疑问句用于对某一情况提出疑问,通常可用yes和no来回答,读时用升调。其基本结构是“be / have / 助动词+主语+谓语(表语)”: Is he interested in going? 他有兴趣去吗? Have you ever been to Japan? 你到过日本吗? Does she often have colds? 她常常感冒吗? Did you ask her which to buy? 你问没问她该买哪一个? 2. 陈述句变一般疑问句的方法 (1) 动词be的否定式。动词be根据不同的时态和人称可以有am, is, are, was, were等不同形式,可用作连系动词(表示“是”、“在”等)和助动词(用于构成进行时态和被动语态等),但不管何种情况,构成疑问式时,一律将动词be的适当形式置于句首: Am I right? 我是对的吗? Are you feeling better today? 你今天感到好些了吗? Was he late for school? 他上学迟到了吗? (2) 动词have的疑问式。动词have根据不同的时态和人称可以有have, has, had等形式,可以用作实意动词和助动词,分以下情况讨论:
①用作实意动词表示状态,如表示拥有、患病或用于have to 表示“必须”等,在构成构成式时可以直接将have, has, had置于句首,也可根据情况在句首使用do, does, did: Does he have [Has he] anything to say? 他有什么话要说吗? Do you have [Have you] to leave so soon? 你必须这么早走吗? Did you have [Had you] any friends then? 他当时有朋友吗? ②用作实意动词表示动作,如表示“吃(=eat)”、“喝(=drin k)”、“拿(=take)”、“收到(=receive)”、“度过(=spend)”等,构成疑问式时不能将have提前至句首,而应在句首使用do, does, did: Does he have breakfast at home? 他在家吃早餐吗? Did you have a good time at the party? 你在晚会上玩得高兴吗? ③用作助动词构成完成时态,其疑问式总是将have等置于句首: Have you finished your work? 你的工作做完了吗? Has he left when you arrived? 你到达时他已离开了吗? (3) 情态动词的疑问式。情态动词的疑问式通常是将情态动词置于句首: Can you speak English? 你会说英语吗?
const,static,extern用法总结
--------------------------CONST--------------------------------------- const应用: 一、对于基本声明 const int r=100;//标准const变量声明加初始化,编译器经过类型检查后直接用100在编译时替换。 二、对于指针 1. int x=10; const int *r=&x; //指针指向的内容是常量,r指向的内容不能够通过r改变,但如果是非const,内容可以通过自己改变,而且r指针可以改变,可以指向其它的整形. //*r=*r+1;NO //x++;YES //r=&y;YES 2. int const *r=&x; 与1完全相同 3. int * const r=&x; //指针指向是常量,不能修改去指向其它内容,但指向的内容可以修改 //r=&y;NO //*r=*r+1;YES //x++;YES 4.const int * const r=&x; //综合1、3用法,r是一个指向常量的常量型指针,指针指向不能改变,指针内容不能改变,内容可以自身改变 //r=&y;NO //*r=*r+1;NO //x++;YES 三、对于类型检查 可以把非const对象赋予const指针,这样就不能改变.但是不能把const赋给非const,除非先强制转换 const int x=100; int *p=(int*)&x; *p++; 四、对于函数 1.void Fuction1(const int r); //此处为参数传递const值,意义是变量初值不能被函数改变 2.const int Fuction1 (int); //此处返回const值,意思指返回的原函数里的变量的初值不能被修改,但是函数按值返回的这个变量被制成副本,能不能被修改就没有了意义,它可以被赋给任何的const或非const类型变量,完全不需要加上这个const关键字。 3.Class CX; //内部有构造函数,声明如CX(int r =0) CX Fuction1 () { return CX(); } const CX Fuction2 () { return CX(); } Fuction1() = CX(1); //没有问题,可以作为左值调用 Fuction2() = CX(1); //编译错误,const返回值禁止作为左值调用。 4.函数中指针的const传递和返回: int F1 (const char *pstr); //作为传递的时候使用const修饰可以保证不会通过这个指针来修改传递参数的初值 const char *F2();//意义是函数返回的指针指向的对象是一个const对象,它必须赋给一个同样是指向const对象的指针 const char * const F3(); //比上面多了一个const,这个const的意义只是在他被用作左值时有效,它表明了这个指针除了指向const对象外,它本身也不能被修改,所以就不能当作左值来处理。 五、对于类 1.首先,对于const的成员变量,只能在构造函数里使用初始化成员列表来初始化,试图在构造函数体内进行初始化const成员变量会引起编译错误。初始化成员列表形如:X:: X ( int ir ): r(ir) {} //假设r是类X的const成员变量 注意:类的构造和析构函数都不能是const函数。 2.建立了一个const成员函数,但仍然想用这个函数改变对象内部的数据。(函数不能修改类的数据成员)
完整word版make用法及短语总结推荐文档
make 用法及短语 、 make 的复合宾语。英语中 make 一词用法甚多,是使用频率最高的动词之一,而 作使役动词的用法也很常见。 意思是“使成为”、“使作为”、“使变成”, 其后的复合宾语 (即 宾语 +宾语补足语)有以下表达方式: 1. make +宾语 +名词(作宾语补足语) Most pop singers make music their career. 大多数流行歌手把音乐当作他们的职业。 Bill Gates ' Microsoft makes him a phenomenon in the business world. 比尔?盖茨的微软使他成为商界的一个奇才。 What makes the ocean such a great place to live? 究竟是什么东西使大海成为如此优越的生活场所呢 European football is played in 80 countries , making it the most popular sport in the world. 80 个国家踢欧式足球,使它成为世界上最受欢迎的运动。 After all , what makes a new invention such a wonderful thing is that it allows us to do something we could not do before . 毕竟, 一项发明之所以成为如此奇妙的事情就在于它可以让我们做以前不能做的事。 2. make +宾语+不带 to 的不定式(作宾语语补足语) Nobody made us go to bed at a certain time. 没有人让我们在某一固定时间就寝。 Pop music makes people feel easy and forget about the real world ; rock music makes people think about the world and how to make their life better . 流行音乐令人松弛安心, 忘记这真实的世界, 而摇滚乐使人思考这个世界和如何改善 自己的生活。 Nothing can make me turn against my country . Love may create the wonder , and may make people become satisfied and optimistic . 爱可以创造奇迹, 可以让人变得满足和乐观。 Children should be made to understand the importance of saving water . 应该让孩子们理解节水的重要性。 3. make +宾语+形容词(作宾语补足语) But I was happy to help because I knew it was to realize our dream of making black and make 什么也不能使我背叛我的祖国。 注意:但改成被动语态时, 则要加 to 。
一般疑问句、选择疑问句的详细用法备课讲稿
一般疑问句、选择疑问句的详细用法
一般疑问句、 (一)一般疑问句 1、一般疑问句概述 一般疑问句(general questions),也可称为“yes/no” questions(是否型问句),因为它一般是由yes或no回答的,如: —Can you swim to the other side?你能游到对岸吗? —Yes, I can.是的,我能。 —No,I can’t.不,我不能。 —Have you locked the door?你锁门了吗? —Yes,I have.是的,锁了。 —No,I haven’t. 不,没有锁。 2一般疑问句的结构 (1)基本的结构为:be/助动词/情态动词+主语+谓语/表语+(其他),句子要读升调,如: Are they your friends?他们是你的朋友吗? Does he go to school on foot?他是步行去上学吗? Will you be free tonight?你今晚有空吗? Can you play basketball?你会打篮球吗? (2)陈述句亦可用作一般疑问句,多用在非正式文体中,句末有问号,用升调,如: Somebody is with you?有人和你一起吗? He didn’t finish the work?他没有做完活吗? You are fresh from America,I suppose?我猜,你刚从美国回来吧? 3、一般疑问句的答语 (1)一般疑问句一般由yes或no来回答,如: —Are you tired?你累了吗? —Yes,I am.是的,累了。 —No, I’m not.不,不累。 —Does she do the cleaning?她扫除了吗?
C++中const用法详解
const是一个C语言的关键字,它限定一个变量不允许被改变。使用const在一定程度上可以提高程序的安全性和可靠性。类型声明中const用来修饰一个常量,有如下两种写法,那么,请问,下面分别用const限定不可变的内容是什么? 1)、const在前面 const int nValue;//nValue是const const char *pContent; //*pContent是const, pContent可变 const (char *) pContent;//pContent是const,*pContent可变 char* const pContent; //pContent是const,*pContent可变 const char* const pContent; //pContent和*pContent都是const 2)、const在后面,与上面的声明对等 int const nValue;// nValue是const char const * pContent;// *pContent是const, pContent可变 (char *) const pContent;//pContent是const,*pContent可变 char* const pContent;// pContent是const,*pContent可变 char const* const pContent;// pContent和*pContent都是const 答案与分析: const和指针一起使用是C语言中一个很常见的困惑之处,在实际开发中,特别是在看别人代码的时候,常常会因为这样而不好判断作者的意图,下面讲一下我的判断原则:当const所在代码段中不包含括号时,沿着*号划一条线,如果const 位于*的左侧,则const就是用来修饰指针所指向的变量,即指针指向为常量;如果const位于*的右侧,const就是修饰指针本身,即指针本身是常量。你可以根据这个规则来看上面声明的实际意义,相信定会一目了然。
make用法及短语总结资料讲解
m a k e用法及短语总结
make用法及短语 一、make的复合宾语。英语中make一词用法甚多,是使用频率最高的动词之一,而make作使役动词的用法也很常见。意思是“使成为”、“使作为”、“使变成”,其后的复合宾语(即宾语+宾语补足语)有以下表达方式: 1. make +宾语+名词(作宾语补足语) Most pop singers make music their career.大多数流行歌手把音乐当作他们的职业。 Bill Gates’ Microsoft makes him a phenomenon in the business world. 比尔·盖茨的微软使他成为商界的一个奇才。 What makes the ocean such a great place to live? 究竟是什么东西使大海成为如此优越的生活场所呢? European football is played in 80 countries, making it the most popular sport in the world. 80个国家踢欧式足球,使它成为世界上最受欢迎的运动。 After all, what makes a new invention such a wonderful thing is that it allows us to do something we could not do before. 毕竟,一项发明之所以成为如此奇妙的事情就在于它可以让我们做以前不能做的事。 2. make +宾语+不带to的不定式(作宾语语补足语) Nobody made us go to bed at a certain time.没有人让我们在某一固定时间就寝。 Pop music makes people feel easy and forget about the real world; rock music makes people think about the world and how to make their life better.
Until的详细用法总结
Until的详细用法总结 你们知道until用法吗?我们一起来学习学习吧,下面就和大家分享,来欣赏一下吧。 Until的用法 比较until和till 此两个连词意义相同。肯定形式表示的意思是"做某事直至某时",动词必须是延续性的。否定形式表达的意思是"直至某时才做某事"。动词为延续性或非延续性都可以。正确使用这两个连词的关键之一就在于判断句中的动词该用肯定式还是否定式。 肯定句: I slept until midnight. 我一直睡到半夜时醒了。 Wait till I call you. 等着我叫你。 (在肯定句中可用before代替Lets get in the wheat before the sun sets.) 否定句: She didnt arrive until 6 oclock.
她直到6点才到。 until 用法上的三个难点 一、 1. until用在肯定句,谓语动词通常是延续性动词,如stand, stay, talk, wait等,表示主句动作终止的时间。如: ③I waited until he cam e back.我一直等到他回来。 ④The war lasted until 1945.战争持续到1945年。 如果用在否定句,谓语动词通常是瞬间性动词,如open, start, leave, arrive, finish, stop等,强调主句动作开始的时间。如: ⑤I didnt leave the boy until his mother turned up.直到这孩子的母亲来,我才离开。 ⑥The noise of the street didnt stop until it wa s midnight.街上的噪音直到半夜才停止。 2.连词until引导的从句中谓语动词的时态 1)until后面的从句中不能用一般将来时,应该用一般现在时代替。所谓的“主将从现”。 He will stay here until his mother comes back.
MAKE的用法
71. Make的用法和判别 一、make作“做”、“制造”、“构成”等解: 1. They make many kinds of machines. 他们制造许多种机器。 2. We made two experiments yesterday. 我们昨天作了两个实验。 3. Hydrogen and oxygen make water. 氢和氧构成水。 4. Two and three make five. 二加三等于五。 5. They are making us a new-type device. 他们正在为我们制造一台新型装置。 二、“make+某些抽象名词”表示作出某种举动。例如: 1. to make an answer 作出答复 2. to make measurement 量度 3. to make efforts to fulfill the plan 努力完成计划 4. to make contributions to the revolution 对革命作出贡献 5. to make adjustments 进行调节 6. to make a calculation 计算 7. to make application 应用,使用 8. to make a correction 校正、更正 9. to make use of…利用…… 10. to make much account of oil 很重视石油 在科技英语中,诸如此类的搭配用法甚多,必须予以注意。翻译时多半译出名词的意思即可。 三、make作“行走”、“行使”解: This automobile makes 70 kilometers an hour. 这辆汽车每小时行驶70公里。 四、“make+直接宾语+宾语补语(名词、形容词、不带to的不定式、过去分词、介词短语等)”,其中make作“使得”、“使……成为”解:
not until的北京中考用法
【中考链接】 1.Not until 1. 托尼经过和老师长时间地反复讨论之后,才下定决心尝试这个新想法。(09西城一模) Tony didn’t ________________________ discussing it with his teacher again and again. 2. 这本小说太长了,我直到昨天才读完。(09丰台二模) The novel was so long _________________________________________ until yesterday. 3. 昨天晚上比尔直到十二点钟才上床睡觉。(09顺义二模) Bill _____________________________ 12 o’clock last night. 4. 昨天下午我直到写完作业才回家。(09石景山模拟) I __________ go home yesterday afternoon ______________ I finished my homework. 5.刘先生过去总抽烟。知道病得严重了,他才戒烟。(11延庆二模) Mr Liu used to smoke a lot.______________ he was seriously ill. 6. 昨天李英洗完衣服才做作业。(11房山一模) Li Ying ________________ her clothes yesterday. 主将从现 1.Be confident! Everyone will succeed if he ___________ in himself. (11 海淀一模) A.believe B. believes C.believed D.will believe 2.You won't have the chance to succeed when you ____________.(11 海淀二模) A.gave up B.give up C. will give up D.are giving up 3.----What will you do tomorrow? (11 西城二模) ----- I will go out for fun if it ___________ fine. A.is B.be C. will be D. Was 4.We ____________ for Dalian as soon as we get the train tickets.(11 东城一模) A.leave B. left C.will leave D.were leaving 4.George will send us an e-mail as soon as he ________in London.(11 东城二模) A.work B.working C. worked D. To work 6.Difficult work___________ easy if you do it very carefully.(11朝阳一模) A.become B.became C.will become D.has become 2.Make 的用法 1.Let's ____________ goodbye to plastic bags in order to protect the environment .(11海淀一模) A. say B. said C. saying D. to say 2.Sarah always makes her son ___________ his hands before eating. (11海淀二模) A.wash B. washed C.washing D.to wash 3.My mother made me ___________ the piano when I was very young . Now, I begin to understand her. (11西城一模) A.play B. to play C. playing D. play 4.----Don't always make Tony ________ this or that. He is already a big boy.(11朝阳一模) ----Maybe you're right. A.do B.done C. to do D.doing 5.让我们忘记分歧,做好朋友吧。(11海淀二模) ____________ forget our differences and be good friends. 6.今天下午没课。让我们去公园吧!(11东城二模) We're free this afternoon.__________ go to the park.
特殊疑问句和一般疑问句的用法
(一)由be(am,is,are)引导的一般疑问句 1、Am I a student? 我是学生吗? Yes,you are./ No,you aren’t. 2、Is this /that/it a chair?这/那/它/是一把椅子吗? Yes,it is. /No,it isn’t. 3、Is she/Amy your sister?她/艾米是你的妹妹吗?Yes,she is ./ No,she isn’t. 4、Is he/Mike your brother?他/迈克是你的哥哥吗?Yes,he is./No,he isn’t. 5、Is your brother helpful at home? 你哥哥在家有用吗?Yes, he is./ No, he isn’t. 6、Is there a forest in the park? 在公园有一个森林吗? Yes,there is./No,there isn’t. 是的,有。/不,没有。 7、Are there any panda s in the mountains?在山上有熊猫吗? Yes,there are./No,there aren’t.是的,有。/不,没有。 8、Are they dusk s? 它们是鸭子吗?(问物) Yes, they are. /No,they aren’t.是的,它们是。/不,它们不是。 9、Are they famers? 他们是农民吗?(问人) Yes, they are. /No,they aren’t. 是的,他们是。/不,他们不是。 10、Are you a teacher?你是一个老师吗?(问you 用I回答) Yes, I am./No,I’m not.是的,我是。/不,我不是。 11、Are you teacher s?你们是老师吗?
Yes,we are./No,we aren’t.是的,我们是。/不,我们不是。 (二)、由do引导的一般疑问句