版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、一、Make a choiceFor the same data type pointer variable, which operator can notused in C program.A. + B. - C. = D.=when0=i10, for the following statements, which reference is wrong to reference array a=1,2,3,4,5,6,7,8,9,0, *p, i;p=a;A. *(a+i) B. ap-a C. p+i D. *(&ai)when0=i10, for the fo
2、llowing statements, which reference is wrong to reference the address of array a=1,2,3,4,5,6,7,8,9,0, *p,i;p=a;A. &(a+1) B. a+ C. &p D. &piWhat is the result for the following program?#include main()int a=1,2,3,4,5,6,*p;p=a;*(p+3)+=2;printf(%d,%dn,*p,*(p+3);A. 0,5 B. 1,5 C. 0,6 D. 1,6wh
3、at is the result for the following program?#include main()(int a12=(1,2,3,4,5,6,7,8,9,10,11,12, *p4,i;for(i=0;i4;i+)pi=&ai*3;printf(%dn,p32);A.輸出項(xiàng)不合法B. 6C. 8D. 12For the following statements, whats the valu(p1-p2)?int a10, *p1, *p2;p1=a;p2=&a5;A. 5 B. 6 C. 10 D.沒(méi)有指針與指針的減法7.for this function prototyp
4、e:void adder(int *ptr,int b);if there are two integers:int op1=2;int op2=4;which statement of function call is right?A:adder(*op1,op2);B:adder(op1,op2);C:adder(&op1,op2);D:adder(&op1,&op2);8.What does the following program outputs to screenvoidToSrn(int *);main()int a=8;int *ptr=&a;ToSrn(ptr);voidTo
5、Srn(int *ptr)printf(%p”,&a);A:compile error,can not be runD:address of a9.Assumingint *p,a=4;p=&a;which of the following statements is all means addressA:a,p+1B:&a,*pC:&a,pD:*a,p10.Assuming inta10,*p; which one is rightA:*p=&a0;B:*p=a;C:p=a0;D:p=&a0;11.Assuming : int a10, *p=a; which one is the addr
6、ess of a9A:a0+9B:&(p+9)C:*(p+9)12.Assuming:char s1=Hello”,s210,*s3=HelloWorld”,*s4;which one of the following statements is correct?A:strcpy(s10,Morning);B:s2=Morning”;C:strcpy(s3,Morning);D:strcpy(s4,Morning);For the following statements, after execution the statement a=p+2;whats the value of a0?fl
7、oat a3=(1.2,45.6,-23.0;float *p=a;A. 1.2 B. 45.6C. -23.0 D.語(yǔ)句有錯(cuò)What format specifiers (in order) should be used in the printf() statement in thefollowing program? Note that in the program the correct format specifiers have beenreplaced by Z.#include int main(void) (int x = 5;int *x_ptr = &x;printf(%
8、Z, %Z, %Z, %Zn, x, *x_ptr, &x, x_ptr);%f, %p, %d, %p%d, %d, %p, %p%d, %p, %d, %p%p, %d, %d, %p二、Fill the blank.the result of printf(%sd”,ab0cd); is 【1】。A pointer is a special type of variable which stores the 【1】 of a memory location.assuming:int a=1,3,5,7,9,11,*p=a; and the value of *p is _ 【1】.the
9、 value of *(a+5) is 【2】For the following statement, int a=8,1,2,5,0,4,7,6,3,9;Whats the valua*(a+a3)?. 二、 read the following programs.On a machine in which addresses are 4 bytes, what is printed by the following program: #include int main(void)char fun = Programming is fun.;char favorite = My favori
10、te class is programming.;char *x = fun;printf(%dn, sizeof(fun);printf(%dn, sizeof(favorite);printf(%dn, sizeof(x);What does the following program print?#include int main(void)int data = 1, 2, 3, 4, 5, 6, 7;int *ptr = data;int i;printf( i *ptrnn);for(i = 2; i -4; i-)printf(%2d, %2dn, i, *ptr);ptr+=i;
11、三、write the following program.1. Rewrite the following program such that the function has a return type of void andthe variable y gets its value using pointers.#include intdbl(intnum);int main(void)int x = 13;x = dbl(x);printf(x doubled is %dn, x);intdbl(intnum)return 2*num;2. Write a program that h
12、as a function that when passed a string will print every fourthcharacterof the string. In main() you should create the string This is an examplestring. and pass this to your function to be printed.Change the program below to print I love programming. You should do this byusing the values in lovetext
13、 to change hatetext. Hint: think about the relationshipbetween the index values of the letters in love and the index values for the word hate.This can be done without creating any new variables.#include int main(void)int i;charhatetext = I hate programming.;charlovetext = love;/* Your code goes here
14、. */ printf(%sn, hatetext);Write a program that has a function that when passed a string will print every fourthcharacter of the string. In main() you should create the string This is an examplestring. and pass this to your function to be printed./*Void printString(char *p);*/Void printString(char *
15、p)Int i=0,len=0,length=strlen(p);While(*p!=NULL&lenlength)Printf(c”,*p);P+=4;Len+=4;main()Char str=This is an examplestring.;printString(str);5./*Write a program.In main(), declare an integer array,and initialize the array through keyboard.Create a multiply() function that when given the array and t
16、he number of array elements,in which can double the value of the array elements( that is ai*2). Also create another print() function for printing the array elements.Call the two functions in main function.Tip: when running the program, input n with 14. */#include #define N 14 void multiply(int a,int
17、 n);void print(int *p);main(void)int aN,i;for(i=0;iN;i+)printf(n No.%d: ,i+1);scanf(%d,&ai);/*(1) call the multiply() function*/*Programmultiply(a,N);End/*(2) call the print() function*/*ProgramPrint(a);Endvoid multiply(int a,int n) int I;/*(3) double the value of the array elements*/Program*/Endvoi
18、d print(int *p)int i;printf(nThe output values after multiply are:n);/*(4) output the value of the array elements*/*ProgramEnd1. Write a program that has a function that when passed a string will print every fourthcharacter of the string. In main() you should create the string ”This is an examplestr
19、ing.” and pass this to your function to be printed./*Void printString(char *p);*/Void printString(char *p)Int i=0,len=0,length=strlen(p);While(*p!=NULL&lenlength)Printf(%c,*p);P+=4;Len+=4;main()Char str=”This is an examplestring.”; printString(str);2./*Write a program.In main(), declare an integer a
20、rray,and initialize the array through keyboard.Create a multiply() function that when given the array and the number of array elements,in which can double the value of the array elements( that is ai*2). Also create another print() function for printing the array elements.Call the two functions in main function.Tip: when running the program, input n
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024高端汽車(chē)租賃服務(wù)詳細(xì)協(xié)議
- 2024導(dǎo)演合作拍攝協(xié)議細(xì)則
- 董事長(zhǎng)的具體職責(zé)職能模板范文5篇
- 2024年度環(huán)保垃圾清運(yùn)服務(wù)協(xié)議模板
- 2024年個(gè)人合伙權(quán)益股份轉(zhuǎn)讓協(xié)議
- 安檢服務(wù)人員2024勞動(dòng)協(xié)議樣本
- 2024年建筑項(xiàng)目安全保證協(xié)議
- 文書(shū)模板-《合伙銷(xiāo)售白酒合同》
- 2024年教育培訓(xùn)業(yè)務(wù)合作協(xié)議
- 2024年度車(chē)輛租賃化三方協(xié)議
- 婦產(chǎn)科學(xué)課件:胎心監(jiān)測(cè)
- 新蘇教版科學(xué)四年級(jí)上冊(cè)學(xué)生活動(dòng)手冊(cè)習(xí)題與講解
- 基礎(chǔ)護(hù)理質(zhì)量標(biāo)準(zhǔn)及考核評(píng)分表
- 商務(wù)條款響應(yīng)表
- 二年級(jí)上冊(cè)美術(shù)教案-7. 去遠(yuǎn)航 -冀教版
- 二年級(jí)上冊(cè)語(yǔ)文課件-10《日月潭》|人教(部編版) (共19張PPT)
- 《詩(shī)情畫(huà)意》教學(xué)設(shè)計(jì)
- 中華文化與傳播教材課件
- Unit3 Sports and Fitness Reading for writing健康生活講義-高中英語(yǔ)人教版(2019)必修第三冊(cè)
- Unit 4 Viewing Workshop 課件-高中英語(yǔ)北師大版(2019)選擇性必修第二冊(cè)
- 血尿尿頻尿急尿痛課件
評(píng)論
0/150
提交評(píng)論