文档库 最新最全的文档下载
当前位置:文档库 › Unit 05 Exercises

Unit 05 Exercises

Unit 05  Exercises
Unit 05  Exercises

Unit 5 Exercises

(1) T r a n s l a t e t h e f o l l o w i n g p a s s a g e i n t o C h i n e s e .

OFDM consists of a large number of subcarriers equally spaced in a frequency band, each may be digitally modulated by a same scheme such as PSK, QAM, etc., or by different schemes. A serially transmitted sequence is divided into a number of sections, each having N symbols, and the N symbols in each section are used to modulate N carriers for simultaneous transmission. Therefore OFDM is essentially a parallel modulation system. When the number of subcarriers is sufficiently large, the system can resist multipath interference. This is because that, in the time domain, a symbol duration longer than the multipath delay can be chosen, while in the frequency domain, each symbol only occupies a small portion of the channel’s frequency band. Thus, the effect of multipath fading spreads over many symbols, resulting in slight distortion to many symbols rather than complete destroy of a few symbols. In this way, correct demodulation is not affected so that the signal can be accurately recovered at the receiver.

In an OFDM system, the principle of choosing the subcarrier interval is to make the subcarriers mutually orthogonal within the entire symbol period. Thus, even if spectral overlap exists between the subcarriers, the symbols can still be recovered without loss. In order to realize maximum spectral efficiency, the interval between subcarriers is usually chosen to equal the reciprocal of the symbol duration T . Therefore the subcarrier frequencies in the base band are f n = n /T , (n = 0, 1, ... , N -1). Denoting the n -th modulating symbol as X (n ), the OFDM waveform within a symbol duration can be expressed as: T t t T n j n X t x N n <≤??? ??=∑-=0,2exp )()(10

π (1) Sampling this waveform at t = T /N yields 1,,2,1,2exp )(2exp )()(1010-=??? ??=??? ??=∑∑-=-=N k N nk j n X N kT j n X k x N n N n ππ (2)

It is observed from the above expression that x (k ) and X (n ) form a discrete Fourier transform pair, therefore the baseband OFDM waveform can be generated from the discrete Fourier transform of N modulating symbols. When N =2m where m is an integer, the fast algorithm of IDFT is easy to implement.

OFDM 由大量在频率上等间隔的子载波构成。每个子载波可用同样的方案,如PSK ,QAM 等,或者用不同的方案数字调制。将串行传输的符号序列分成许多段,每一段有N 个符号,每段的N 个符号被用来分别调制N 个载波同时发送。因此,OFDM 本质上是一个并行调制系统,当载波数足够大时,这种系统具有抗多径干扰的能力。这是因为在时域上符号周期能选取得比多径延迟时间长,而在频域上每个符号只占整个信道带宽的一小部分,因此多径衰落的影响被分散到许多符号上,其结果是许多符号都发生轻度的畸变,而不是使某些符号被完全破坏。这样,不影响正确的解调,信号能在接收器中准确地恢复。

在OFDM 系统中,选择子载波间隔的原则是使子载波在整个符号周期内相互正交,这样。即使在子载波间存在频谱部分重叠,符号仍能无损失地恢复。为了实现最大的频谱效率,子载波之间的间隔通常选取为符号周期的倒数。因此基带子载波频率为f n = n /T , (n = 0, 1, ... , N -1),第n 个调制符号记为X (n ),在一个符号周期内的OFDM 波形可表示:

T t t T n j n X t x N n <≤??? ??=∑-=0,2exp )()(10

π (1)

在t = T /N 时刻采样这个波形得到: 1,,2,1,2exp )(2exp )()(1010-=??? ??=??? ??=∑∑-=-=N k N nk j n X N kT j n X k x N n N n ππ (2)

从上面的表示中可以看到,x (k ) 和X (n )构成了一对离散傅里叶变换,因此基带OFDM 波形可根据N 个调制符号的离散傅里叶变换来生成。当N =2m ,其中m 为整数,IDFT 的快速算法很容易实现。

(2) C h o o s e t h e w o r d o r p h r a s e t h a t i s c l o s e s t i n m e a n i n g t o t h e u n d e r l i n e d p a r t .

1. The process gain of a system indicates the gain or signal to noise improvement exhibited by a spread spectrum system by the nature of the spreading and despreading process.

A. by virtue of the spreading/dispreading process

B. by processing the spreading/despreading naturally

C. according to the spreading/despreading characteristics

D. using the natural spreading/dispreading process

2. Due to the unavoidable timing errors between the users, there is little point in using Walsh codes as they will no longer be orthogonal. A. using Walsh codes will have some point due to the absence of orthogonality

B. using Walsh codes is meaningless since orthogonality will not exist any more

C. Walsh code cannot be used since they are not orthogonal

D. it is unnecessary to use Walsh codes because orthogonality is lost 3. For example, when a part of the channel bandwidth is faded, frequency interleaving ensures that the bit errors that would result from those subcarriers in the faded part of the bandwidth are spread out in the bit-stream rather than being concentrated.

A. that would be produced in those subcarriers suffering from frequency selective fading

B. that would cause some subcarriers being faded in some part of the bandwidth

C. that would came from the fading subcarriers falling in part of the bandwidth

D. that would result in those faded subcarrier of the part of the bandwidth

4. The basic idea of applying the beamformer technique to this approach is very promising and might give a significant improvement for source localization.

A. might obtain formidable gain in local sources

B. provide possibilities to substantially enhance source locations

C. might present a major advance in localizing sources

D. is likely to considerably refine techniques to locate sources

5. Early we introduced the concept that the identity of an amplitude modulated message signal may under certain circumstances be communicated by transmitting regular samples of the message, rather than the continuous signal.

A. values of the message signal taken at regular intervals

B. formally obtained message samples

C. samples of the message produced in a specific manner

D. samples of the regularly obtained message

6. Having defined these functions, we will proceed to show how they can be used to evaluate certain integrals characteristic of system error performance.

A. evaluate characteristics of certain integrals in system error performance

B. assess certain integrals that are typical in describing error performance of the systems

C. decide the value of some characteristic integrals of error performance of the systems

D. carry out evaluations on the integrated characteristics of system error performance

7.Modulation is the systematic variation of some attribute of a carrier waveform such as the

amplitude, phase, or frequency in accordance with a function of the message signal.

A. in terms of a message carried by the signal

B. according to the behavior of the signal

8.Over recent years this potential has largely been realized in the costs of the optical fiber

transmission medium that for bulk purchases is now becoming competitive with copper wires.

A. that is specifically for purchases, and is becoming superior to copper wires

B. that is bulkily comparable in price with copper wires

C. that is competing with copper wires in terms of the scale of purchases

D. that is becoming a challenge to copper wires when bought in a large quantity

指针数组及指向一维数组的指针讲解

一、指针数组及指向一维数组的指针(数组指针)讲解 1、数组指针(也称行指针) 定义 int (*p)[n]; ()优先级高,首先说明p是一个指针,指向一个整型的一维数组,这个一维数组的长度是n,也可以说是p的步长。也就是说执行p+1时,p要跨过n个整型数据的长度。 如要将二维数组赋给一指针,应这样赋值:int a[3][4];int (*p)[4]; //该语句是定义一个数组指针,指向含4个元素的一维数组。 p=a; //将该二维数组的首地址赋给p,也就是a[0]或&a[0][0] p++; //该语句执行过后,也就是p=p+1;p跨过行a[0][]指向了行a[1][] 所以数组指针也称指向一维数组的指针,亦称行指针。 2、指针数组 定义 int *p[n]; []优先级高,先与p结合成为一个数组,再由int *说明这是一个整型指针数组,它有n个指针类型的数组元素。这样赋值是错误的:p=a;只存在p[0]、p[1]、p[2]...p[n-1],而且它们分别是指针变量可以用来存放变量地址。但可以这样 *p=a; 这里*p表示指针数组第一个元素的值,a的首地址的值。 如要将二维数组赋给一指针数组: int *p[3]; int a[3][4]; for(i=0;i<3;i++) p[i]=a[i]; 这里int *p[3] 表示一个一维数组内存放着三个指针变量,分别是p[0]、p [1]、p[2]所以要分别赋值。 这样两者的区别就豁然开朗了,数组指针只是一个指针变量,似乎是C语言里专门用来指向二维数组的,它占有内存中一个指针的存储空间。指针数组是多个指针变量,以数组形式存在内存当中,占有多个指针的存储空间。 还需要说明的一点就是,同时用来指向二维数组时,其引用和用数组名引用都是一样的。 比如要表示数组中i行j列一个元素: *(p[i]+j)、*(*(p+i)+j)、(*(p+i))[j]、p[i][j] 优先级:()>[]>* 例1、下列给定程序中,函数fun()的功能是:从N个字符串中找出最长的那个串,并将其地址作为函数值返回。 #include #include #define N 4

数组名和指针的区别(小结)

在Win 32 中: 1. (1) 对数组名进行sizeof运算时,结果是整个数组占用空间的大小; (2) 但是数组作为函数参数时,对数组名进sizeof 运算,结果为4; (2) 对指针进行sizeof运算得到的值是编译器分配给指针(也就是一个地址)的内存空间,即为4。 2. (1) 对数组名作&运算,得到的还是数组第一个元素的地址; (2) 对指针取地址时得到的结果是指针所在的地址,也就是指向这个指针的指针,与指针的值不同。 BOOL mytest(char param[100]) { //参数数组名:paramBytes int paramBytes = sizeof(param); printf("paramBytes \t%d\n",paramBytes); //数组:mych1[] char mych1[] = "abcdefg123"; //若定义为mych1[100] int mych1Bytes = sizeof(mych1); printf("mych1Bytes \t%d\n",mych1Bytes);//输出:100 //数组:mych[200] char mych[200] = {0}; int myBytes = sizeof(mych); printf("myBytes \t%d\n",myBytes); printf("---addr \t%d\n",mych); printf("---addr \t%d\n",&mych); //指针:pch char* pch = "12345abc"; int pchBytes = sizeof(pch); printf("pchBytes \t%d\n",pchBytes); //pch = mych; printf("---addr \t%d\n",pch); printf("---addr \t%d\n",&pch); return TRUE; } 运行:

语言学概论Chapter+1+Exercises

Chapter 1 Introduction I. There are four choices following each statement. Mark the choice that can best complete the statement. 1. If a study describes and analyzes the language people actually use, it is said to be ______________. A. prescriptive B. analytic C. descriptive D. linguistic 2. Which of the following is not a design feature of human language? A. Arbitrariness B. Displacement C. Duality D. Meaningfulness 3. Modern linguistics regards the written language as ____________. A. primary B. correct C. secondary D. stable 4. In modern linguistics, speech is regarded as more basic than writing, because ___________. A. in linguistic evolution, speech is prior to writing B. speech plays a greater role than writing in terms of the amount of information conveyed. C. speech is always the way in which every native speaker acquires his mother tongue. D. All of the above 5. A historical study of language is a ____ study of language. A. synchronic B. diachronic C. prescriptive D. comparative 6. Saussure took a(n) __________ view of language, while Chomsky looks at language from a ________ point of view. A. sociological, psychological B. Psychological, sociological C. applied, pragmatic D. semantic, linguistic 7. According to F. de Saussure, ____ refers to the abstract linguistic system shared by all the members of a speech community. A. parole B. performance C. Langue D. language 8. Language is said to be arbitrary because there is no logical connection between _________ and meanings. A. sense B. Sounds C. objects D. ideas 9. Language can be used to refer to contexts removed from the immediate situations of the speaker. This feature is called_________. A. displacement B. duality C. flexibility D. cultural transmission

指针与数组练习题

指针与数组练习题 1、下面程序实现如下功能:输入一个整数字符串转换为一个整数值,如”1234”转换为1234,”-1234”转换为-1234。读懂main函数,编写转换函数chnum #include #include void main() { char s[6]; int n; int chnum(char *p); gets(s); if (*s=='-') n=-chnum(s+1); else n=chnum(s); printf("%d\n",n); } int chnum(char*p) { int sum=0; while(*p!='\0') { if(*p>='0'&&*p<='9') sum=sum*10+*p-'0'; p++; } return sum; } 2、从键盘输入一个字符串,去掉所有非十六进制字符后转换成十进制数输出。读懂以下main函数,编写相应的函数del16和htod。 #include #include void main() { char s1[10],s2[10]; void del16(char*,char*); int htod(char*); gets(s1); //读入一字符串 del16(s1,s2); //去掉所有非十六进制字符到s2 printf("%d\n",htod(s2)); //把s2转换为10进制 }

void del16(char*s1,char*s2){ for(;*s1!='\0';s1++) if(*s1>='0'&&*s1<='9'||*s1>='a'&&*s1<='f'||*s1>='A'&&*s1<='F'){ *s2 = *s1; s2++;} *s2='\0'; } int htod(char*s2){ int sum=0; for(;*s2!='\0';s2++){ if(*s2>='0'&&*s2<='9') sum=sum*16+*s2-'0'; else if(*s2>='a'&&*s2<='f') sum=sum*16+*s2-'a'+10; else if(*s2>='A'&&*s2<='F') sum=sum*16+*s2-'A'+10; } return sum; } 3、编写函数insert(char *s1,char *s2,int pos),实现在字符串s1中的指定位置pos处插入字符串s2。 Happy Year New 7 Happy New Year #include #include int main(void) { void insert(char *s1,char *s2,int pos); char s1[80],s2[80]; int pos; gets(s1); gets(s2); scanf("%d",&pos); insert(s1,s2,pos); puts(s1); return 0; } void insert(char *s1,char *s2,int pos) {

实验三 数组与指针实验

实验三数组与指针实验 【实验目的】 1.学习使用数组数据对象。 2.掌握指针的使用方法。 3.学习通过动态内存分配实现动态数组的定义和使用,并体会指针在其中的作用。4.练习通过Debug观察指针的内容及其所指对象的内容。 【实验内容】 1.运行下列程序,观察运行结果。 (1)#include class ArrayElem { int x; public: ArrayElem(int i){x=i;} //带参数的构造函数 int getx(){return x;} }; int main() { ArrayElem obs[4] ={-1,-2,-3,-4}; //创建对象数组并初始化 for(int i=0;i<4;i++) cout<<"obs["< class NumClass { int num; public: void set_num(int val){num=val;} void show_num(){cout<<"The num is :"<set_num(20);p->show_num(); //通过指针调用成员函数 return(0); } (3)#include class NumClass

语言学Chapter课后练习答案

Chapter 4 Revision Exercises 1. What is syntax? Syntax is a branch of linguistics that studies how words are combined to form sentences and the rules that govern the formation of sentences. 2. What is phrase structure rule? The grammatical mechanism that regulates the arrangement of elements (i.e. specifiers, heads, and complements) that make up a phrase is called a phrase structure rule. The phrase structural rule for NP, VP, AP, and PP can be written as follows: NP→(Det) N (PP) ... VP→(Qual) V (NP) ... AP→(Deg) A (PP) ... PP→(Deg) P (NP) ... We can formulate a single general phrasal structural rule in which X stands for the head N, V, A or P. The XP rule: XP→(specifier) X (complement) 3. What is category? How to determine a word’s category? Category refers to a group of linguistic items which fulfill the same or similar functions in a particular language such as a sentence, a noun phrase or a verb. To determine a word's category, three criteria are usually employed, namely meaning, inflection and distribution. The most reliable of determining a word’s category is its distribution. 4. What is coordinate structure and what properties does it have? The structure formed by joining two or more elements of the same type with the help of a conjunction is called coordinate structure. It has four important properties: 1)there is no limit on the number of coordinated categories that can appear prior to the conjunction. 2) a category at any level (a head or an entire XP) can be coordinated. 3)coordinated categories must be of the same type. 4)the category type of the coordinate phrase is identical to the category type of the elements being conjoined. 5. What elements does a phrase contain and what role does each element play? A phrase usually contains the following elements: head, specifier and complement. Sometimes it also contains another kind of element termed modifier. The role each element can play:

第七章字符数组与指针练习题参考答案

第七章字符数组与字符串 【题7.29】下面是对s的初始化,其中不正确的是。 A)char s[5]={“abc”};B)char s[5]={‘a’,‘b’,‘c’}; C)char s[5]=“”;D)char s[5]=“abcdef”; 【题7.30】下面程序段的运行结果是。 char c[5]={‘a’,‘b’,‘\0’,‘c’,‘\0’}; printf(“%s”,c); A)‘a’‘b’ B)ab C)ab c 【题7.31】对两个数组a和b进行如下初始化 char a[]=“ABCDEF”; char b[]={‘A’, ‘B’,‘C’,‘D’,‘E’,‘F’}; 则以下叙述正确的是。 A)a与b数组完全相同B)a与b长度相同 C)a和b中都存放字符串D)a数组比b数组长度长 提示:‘\0’是字符串结束的标志 【题7.32】有两个字符数组a、b,则以下正确的输入格式是。 A)gets(a,b); B)scanf(“%s %s”,a,b); C)scanf(“%s %s”,&a,&b);D)gets(“a”),get(“b”); 【题7.33】有字符数组a[80]和b[80],则正确的输出形式是。 A)puts(a,b); B)printf(“%s %s”,a[],b[]); C)putchar(a,b); D)puts(a),puts(b); 【题7.34】下面程序段的运行结果是。 char a[7]=“abcdef”; char b[4]=“ABC”; strcpy(a,b); printf(“%c”,a[5]); A)空格B)\0 C)e D)f 提示:复制后a[0]=‘A’,a[1]=‘B’,a[2]=‘C’,a[3]=‘\0’, a[4]=‘e’,a[5]=‘f’, a[6]=‘\0’,

变量的指针和指针变量的区别是什么

2变量的指针和指针变量的区别是什么。 答;一个变量的地址指出了变量的存储单元在内存中的具体位置,能对变量进行存取操作。这个变量的地址就是变量的指针。指针是一种具有特殊意义的整型数,指针不能存放在一般的整型变量中,必须存放在专门指针的变量中,这类变量就是指针变量。 3 一维数组元素的引用有哪些方式。 答;下标法、地址法、指针法 4 2维数组列地址有哪些计算方法。 答;1 根据数组元素所在的行计算出行地址,然后把行地址转换成行中首元素的地址,再根据数组元素所在的列计算数组元素的地址。 2 根据2维数组的数组元素在存储空间上按行连续存放的特点,每个数组元素的地址等于2维数组元素的首元素地址加上该数组元素相对于首元素位置的偏移量。 3把2维数组的每一行当作一个一维数组,用一维数组元素地址的计算方法计算相应的2维数组元素的地址。 第9章结构体与共用体 1 什么是链表。其中单向链表具有哪些特点。 答;链表是若干个同样类型的结构通过依次串接方式构成的一种动态数据结构。链表中的每一个结构体数据成为结点,链表可以分成单向链表和双向链表 单向链表的特点;1 链表中的结点数据可以改变的 2 结点占用的内存是动态分配内存和动态释放内存函数。 2 对单向链表的常用操作有哪些。 答;对单向链表的常用操作有建立、显示、插入,删除和查找。 3 什么是共用体。 答;共用体是一个集合体。它的各个成员的数据类型可以是不相同的,所有成员共享同一段存储空间,存储空间的大小取决存储单元最大的成员的数据类型。 4 指向结构体类型变量的指针变量引用形式有哪些。 答;有两种形式;【星号指针变量名】。成员名和指针变量名-大于号成员名。 第10章位运算及编译预处理 1 C提供的编译预处理功能有哪些。如何实现。 答;功能有三种;宏定义、文件包含和条件编译,分别用宏定义命令、文件包含命令、条件编译命令实现。 2 文件包含的基本功能是什么。 答;文件包含处理是一个源文件可以将另一个源文件的全部内容包含到本文件中来,作为本文件的一部分,这可以节省程序设计人员的重复劳动。 【3【在C语言中提供了几种什么样的位运算符。 答;-、小于小于、大于大于、 4 文件包含需要注意哪些问题 答;一个井include命令只能指定一个被包含文件,包含多个文件侧需多个井include命令;文件包含可以嵌套,即一个被包含文件中可以包含另一个被包含的文件;在井include命令中,文件名可以用双引号或尖括号括起来。 第11章文件 1 文件的结束标志有哪些。 答;每个文件都有一个结束标志。当文件的位置指针移到文件的结束标志处时,表示文件结束。如何测试文件是否结束,常有2种方法 1 ASCII码文件的结束标志用【-1】表示。

语言学练习Exercise 5

E111 1125110312 张翩翩 Exercise 5 I. State whether each of the following statements is True or False. (30 points) F 1. A grammatical sentence is also meaningful. F 2. Some words are always superordinates while some others are always hyponyms. F 3. Synonyms are those words that can be used interchangeably in all contexts. F 4. Antonyms have opposite meanings. F 5. All English words have their referents. T 6. The principle of compositionality refers to the idea that the meaning of a sentence depends on the meanings of the constituent words and the way they are combined. T 7. One advantage of componential analysis is that by specifying the semantic features of words, it will be possible to show how these words are related in meaning. F 8. In the classic semantic triangle, the symbol is directly related to the referent. T 9. The superordinate term is more inclusive in meaning than its hyponyms. T 10. To understand a sentence, we need knowledge about its syntactic structure and the meanings of the words used in it. II. Give the respective antonym for each of the following words and then tell to which category they belong. (32 points) 1. boy – ( girl ) ( complementary antonymy ) 2. wide – (narrow) (gradable antonymy) 3. lengthy –(brief ) (gradable antonymy) 4. thin – ( thick) (gradable antonymy ) 5. dead – (alive ) (complementary antonymy) 6. interviewer – (interviewee ) (converse antonymy) 7. sell – (buy) (converse antonymy) 8. teacher – (student ) (converse antonymy) III. Study the following pairs of words. What is the sense relation between these pairs of words? (18 points) (1) shallow / deep ( antonymy ) (2) mature / ripe ( synonymy)

语言学试题

I. Decide whether each of the following statements is True or False: 1. Linguistics is generally defined as the scientific study of language. 2. Linguistics studies particular language, not languages in general. 3. A scientific study of language is based on what the linguist thinks. 4. In the study of linguistics, hypotheses formed should be based on language facts and checked against the observed facts. 5. General linguistics is generally the study of language as a whole. 6. General linguistics, which relates itself to the research of other areas, studies the basic concepts, theories, descriptions, models and methods applicable in any linguistic study. 7. Phonetics is different from phonology in that the latter studies the combinations of the sounds to convey meaning in communication. 8. Morphology studies how words can be formed to produce meaningful sentences. 9. The study of the ways in which morphemes can be combined to form words is called morphology. 10. Syntax is different from morphology in that the former not only studies the morphemes, but also the combination of morphemes into words and words into sentences. 11. The study of meaning in language is known as semantics. 12. Both semantics and pragmatics study meanings. 13. Pragmatics is different from semantics in that pragmatics studies meaning not in isolation, but in context. 14. Social changes can often bring about language changes. 15. Sociolinguistics is the study of language in relation to society. 16. Modern linguistics is mostly prescriptive, but sometimes descriptive. 17. Modern linguistics is different from traditional grammar. 18. A diachronic study of language is the description of language at some point in time. 19. Modern linguistics regards the written language as primary, not the spoken language.

C语言中指针、数组和引用例子实例

一、指针:内容是指示一个内存地址的变量;类型是指示编译器怎么解释指针内容指向地址中的内容,以及该内存区域有多大; 例子: [cpp] int i = 0; int * pi = &i; printf(“pi = %x \n”, pi); // 打印pi的内容: 0x2000 printf(“*pi= %d \n” , *pi); // 打印pi指向地址中的值: 5 printf(“&pi= %x \n”, &pi); // 打印pi的地址: 0x100 从汇编的角度来看,指针是这样的: int i = 0; 010E139E mov dword ptr [i],0 int * pi = &i; 010E13A5 lea eax,[i] 010E13A8 mov dword ptr [pi],eax 二、数组:是一个单一数据类型对象的集合。其中单个对象没有被命名,通过索引访问。 数组名和指针的区别:数组名的内涵在于其指代实体是一种数据结构,这种数据结构就是数组。数组名的外延在于其可以转换为指向其指代实体的指针,而且是一个指针常量。指向数组的指针则是另外一种变量类型,仅仅意味着数组的存放地址 注意:虽然数组名可以转换为指向其指代实体的指针,但是它只能被看作一个指针常量,不能被修改,如下:天骄无双:https://www.wendangku.net/doc/968119520.html, [cpp] int intArray[10]; intArray++; // 错误 “指针和数组等价”说的是什么?索引操作相同,例如:p[2]; a[2]; 三、引用(reference)是一个对象的别名。用对象初始化引用后,对象的名字和引用都指向该对象; 引用是如何实现的?从汇编语言的角度来看,指针和引用是一样的: [cpp] int i = 0; 00E9139E mov dword ptr [i],0 int & ref = i; 00E913A5 lea eax,[i] 00E913A8 mov dword ptr [ref],eax int * pi = &i; 00E913AB lea eax,[i] 00E913AE mov dword ptr [pi],eax 指针和引用的区别(从C++使用角度来看): 不存在空引用 引用要初始化 引用初始化后,不能指向另一个对象 这是由编译阶段保证的。 备注:一个指向非常量的引用不能用字面值或者临时值初始化;但是一个指向常量的引用可以。天骄无双:https://www.wendangku.net/doc/968119520.html,

上机实验十 指针与数组

上机实验十指针与数组 学号: 姓名: 一、目的要求: 1.了解或掌握指针与数组的关系,指针与数组有关的算术运算、比较运算。 2.了解或掌握运用指针处理数组。 二、实验内容: 第1题、分别用下标法和指针变量p访问数组a[5]={1,3,5,7,9},至少用三种方法输出数组各元素的值,每种方法输出的五个元素在一行上。 第2题、书上P211例10-4。并仔细体会P212“使用指针实现数组元素逆序存放”的指针移动思想。 第3题、编写程序,使用指针实现逆序打印一维整型数组所有元素的操作。 数组a: 1 3 7 2 9 6 5 8 2 0 4 8 2 0 4 第4题、书上P213冒泡排序。 第5题、编写一个函数s(a,n),其中a是一个指向整型的指针接受一维整型数组首地址,n 是数组长度,功能是通过指针求数组中元素的平均值,并编写主函数测试函数。 第6题、编写一个函数void sort(int *a, int n), 用选择法对数组a中的元素按降序排序。在main()函数中输入10个数,调用sort函数排序后,然后输出。

第7题、使用指针把从键盘输入的2个数按从大到小的顺序输出(不改变变量的值),请补充完整并上机调试。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 第8题、输入10个整数存入一维数组,然后逆置数组,最后输出。下面给出部分程序的内容,请将程序补充完整,然后上机调试。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 第9题、上机调试下面程序,看哪些程序实现了交换主函数中两个变量值的操作,哪些没有实现,并分析原因。 第10题、调试修改下面程序,函数fun的功能是:在含有10 个元素的s数组中查找最大数,及最大数所在位置(即,下标值),最大数可能不止一个。最大数作为函数值返回,最大数的个数通过指针变量n传回,所在位置由数组pos传回。例如: 若输入 2 8 5 7 8 4 5 3 2 8 则应输出:The max: 8 The positions: 1 4 9 请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。

C语言指针数组函数练习(含参考答案)

作业(使用指针、数组、函数完成) 1. 编写一个通用函数,该函数可以实现判断:一个含有五位数字的整数是否是回文数。回文数的含义是从左向右与从右向左看,数是相同的。如:23732是回文数,而23564则不是。编写主程序调用该函数实现求所有5位数字中满足条件的数的个数。 #include int Judge(int num) { int w,q,b,s,g; w=num/10000; q=num%10000/1000; s=(num%100)/10; g=num%10; if((w==g)&&(q==s)) return 1; else return 0; } void main() { int count=0; int i; for(i=10000;i<=99999;i++) if(Judge(i)) count++; printf("%d\n",count); } 2.编写一个通用函数,该函数可以实现对数值型数组的倒序。倒序的含义是把数组的元素值前后颠倒。例数组:20,19,18,15,13,10倒序的结果为:10,13,15,18,19,20。编写主程序,数组初始化方式不限,并输出,然后调用该函数实现倒序后再输出倒序的结果。#include #define N 6 void Transfer(double *b,int n) { double temp; double *i=b; double *j=b+n-1; while(j>i) { temp=*i; *i=*j; *j=temp; i++;

j--; } } void main() { double array[N]={20,19,18,15,13,10}; int i; for(i=0;i #include double Cal(double *p,int n) { int i,j; double sum=0; for(i=0;i

指针与数组 函数的组合

指针和数组 ? ? 1.指针数组:是其数组元素为指针的数组。记住:是一个存放着指针的数组,而不是一个指针 ?定义格式为:数据类型* 数组名[数组长度] ?如:int * a[10] ; [ ]的优先级高于*,意味着使得a是一个指针数组,表示具有10个元素的数组,每个元素是一个指向int 型的指针。 ? ?2,指向数组的指针:是一个指针,指向的是一个数组。 ?定义格式为:数据类型(*数组名) [数组长度] ?如:int (*a) [10];*先于a 结合,意味着a 是一个指针,指向具有10个int 值的数组, ? ? ?指针与函数 ? ?1, 函数的指针:首先它是一个指针,指向函数的入口地址;在C语言中,函数名就是来标识函数的入口地址。 ?与指向数组的指针不同,在数组中,可以对数组中的元素访问,可以进行算术运算。 而在函数中,只需考虑函数的入口地址,而不考虑函数中某具体指令或数据所在存 储单元的地址,即不能进行算术运算 ?定义格式:存储类型数据类型(*函数名) ( ) ?如:static int (*p) (); ?存储类型表示函数在文件中的存储方式 ?数据类型表示被指函数的返回值的类型 ?最后的空括号表示指针变量所指的是一个函数 ? ?如何用指向函数的指针变量的方式来调用相应的函数: ?1), 使用前,必须先定义并赋值 ?2), 指向函数的指针定义形式中的数据类型必须和赋给它的函数返回值类型相同 ?3), 指向函数的指针只能指向函数的入口,而不能使用*(p+1) 来表示函数的下一命令?4), 在函数指针赋值时,只需给出函数名而不需给参数,如p = max; ?5), 调用时,只需将(*p) 代替函数名即可,在p 后面的括号中根据需要写上实参,如: c = (*p) (a,b) ; ?如下程序:求直角三角形的斜边 ?#include ? #include ?main() ?{ ? int a ,b ,c , f() , (*f1)(); ? a = 3; b = 4;

C语言笔记第五章数组和指针的关系

C语言笔记第五章数组和指针的关系 第五章数组和指针的关系 如果对声明数组的语句不太明白的话,请参阅我前段时间贴出的文章< 理解c和c++的复杂类型声明>>。 数组的数组名其实可以看作一个指针。看下例: 例八: int array[10]={0,1,2,3,4,5,6,7,8,9},value; ... ... value=array[0];//也可写成:value=*array; value=array[3];//也可写成:value=*(array+3); value=array[4];//也可写成:value=*(array+4); 上例中,一般而言数组名array代表数组本身,类型是int [10],但如果把a rray看做指针的话,它指向数组的第0个单元,类型是int *,所指向的类型是数组单元的类型即int。因此*array等于0就一点也不奇怪了。同理,array+3是一个指向数组第3个单元的指针,所以*(array+3)等于3。其它依此类推。 例九: 例九: char *str[3]={ "Hello,this is a sample!", "Hi,good morning.", "Hello world" }; char s[80]; strcpy(s,str[0]);//也可写成strcpy(s,*str); strcpy(s,str[1]);//也可写成strcpy(s,*(str+1)); strcpy(s,str[2]);//也可写成strcpy(s,*(str+2));

上例中,str是一个三单元的数组,该数组的每个单元都是一个指针,这些指 针各指向一个字符串。把指针数组名str当作一个指针的话,它指向数组的第0号单元,它的类型是char**,它指向的类型是char *。 *str也是一个指针,它的类型是char*,它所指向的类型是char,它指向的地 址是字符串"Hello,this is a sample!"的第一个字符的地址,即'H'的地址。 str+1也是一个指针,它指向数组的第1号单元,它的类型是char**,它指向 的类型是char *。 *(str+1)也是一个指针,它的类型是char*,它所指向的类型是char,它指向"Hi,good morning."的第一个字符'H',等等。 下面总结一下数组的数组名的问题。声明了一个数组TYPE array[n],则数组 名称array就有了两重含义:第一,它代表整个数组,它的类型是TYPE [n];第二,它是一个指针,该指针的类型是TYPE*,该指针指向的类型是TYPE,也就是数组单元的类型,该指针指向的内存区就是数组第0号单元,该指针自己占有单独的内存区,注意它和数组第0号单元占据的内存区是不同的。该指针的值是不能修改的,即类似array++的表达式是错误的。 在不同的表达式中数组名array可以扮演不同的角色。 在表达式sizeof(array)中,数组名array代表数组本身,故这时sizeof函数 测出的是整个数组的大小。 在表达式*array中,array扮演的是指针,因此这个表达式的结果就是数组第 0号单元的值。sizeof(*array)测出的是数组单元的大小。 表达式array+n(其中n=0,1,2,....。)中,array扮演的是指针,故arr ay+n的结果是一个指针,它的类型是TYPE*,它指向的类型是TYPE,它指向数组第n号单元。故sizeof(array+n)测出的是指针类型的大小。 例十: int array[10]; int (*ptr)[10]; ptr=&array; 上例中ptr是一个指针,它的类型是int (*)[10],他指向的类型是int [10] ,我们用整个数组的首地址来初始化它。在语句ptr=&array中,array代表数组本身。

相关文档