c语言程序设计基础实验报告8.docx

  1. 1、本文档共6页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
#i ncludestdio.h #i ncludestdio.h void mai n() { int x=10,y=5,*px,*py; px=x; py=y; prin tf(px=%d,py=%d,*px,*py); } 实验8指针 一、 实验目的 1、 通过实验进一步掌握指针的概念,会定义和使用指针变量; 2、 能正确使用数组的指针和指向数组的指针变量; 3、 能正确使用字符串的指针和指向字符串的指针变量; 二、 实验内容和步骤 1、改错 (1)指出下面程序错误的原因? main () { int x=10,y=5,*px,*py; px=py; px=x; py=y; prin tf(*px=%d,*py=%d,*px,*py); } (2)下面的程序试图有如下运行结果 : which style you want to : Capital ( c ) or un capital ( a ):c / COMPUTER Which sytle you want to : Capital ( c ) or un capital ( a ) : u/ computer请调试下面的程序, Capital ( c ) or un capital ( a ) : u/ computer 请调试下面的程序,使其有如上执行结果? #i nclude main () { char s*;char c; printf(which style you want to :ln”); prin tf(capital ( c ) or un capital(a):); c=getchar(); if(c=c)strcpy(s,COMPUTER); else strcpy(s,computer); put(s); } #in cludestdio.h #i ncludevstri ng.h #in cludestdlib.h void mai n() { char *s;char c; prin tf(which style you want to :\n); prin tf(capital(c) or un capital(a):); c=getchar(); 剧 』口1 1 uhich stifle w vant to * capi^Kc or uncapi^A l?i : a romvuter Press anil k总y xo continue il s=calloc(20, sizeof(char)); 〃分配存储空间 strcpy(s,computer); if(c==c) puts(s); strcpy(s,COMPUTER); } else (3)下面的程序能获得上述运行结果吗 mai n() #i ncludestdio.h {char *S=COMPUTER; void mai n() char c; { char *s=COMPUTER; prin tf(which style you want to \n); char c; prin tf(capital (c) or un capital(u);); prin tf(which style you want to:\n); c=getchar(); prin tf(capital(c) or un capital(u);); if(c=c) c=getchar(); put(s); if(c==c) else { puts(s); s=computer; else puts(s); { s=computer; } puts(s); } } } (4)设计一个C程序,用以测试下列各表达式的运算 ? (1) y=*px++ ⑵ y=*++py ⑶ y=(*py)++ (4) y=--*ppx++ (5)想使指针变量pt1指向a和b中的大者,pt2指向小者,以下程序能否实现此目的 swap( int *p1,i nt *p2){int *p;p=p1;p 仁 swap( int *p1,i nt *p2) {int *p; p=p1;p 仁p2;p2=p; } mai n() {int a,b; pt1=a;pt2=b; if(ab) swap (pt1.pt2); prin tf(%d,%d\n,*pt1,*pt2); } #in cludestdio.h scan f(%d,%d,a,b); void swap(i nt *p1, int *p2) pt1= a; pt2=b; { in t p; if(ab) p=*p1;*p1=*p2;*p2=p; swap (pt1,pt2); } prin tf(%d,%d\n,*pt1,*pt2); void mai n(

文档评论(0)

xiaozu + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档