大連東軟信息學(xué)院C語言指針練習(xí)2016x_第1頁
大連東軟信息學(xué)院C語言指針練習(xí)2016x_第2頁
大連東軟信息學(xué)院C語言指針練習(xí)2016x_第3頁
大連東軟信息學(xué)院C語言指針練習(xí)2016x_第4頁
大連東軟信息學(xué)院C語言指針練習(xí)2016x_第5頁
已閱讀5頁,還剩11頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

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.沒有指針與指針的減法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.語句有錯(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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論