c++指针类练习题及答案.pdfVIP

  • 260
  • 0
  • 约6.93千字
  • 约 13页
  • 2022-07-20 发布于广西
  • 举报
c++指指针针类类练练习习题题及及答答案案 1、利⽤指针,编写⽤于交换两个整型变量值的函数。程序 ⾏结果如下:输⼊:5 6 输出:6 5 #include using namespace std ; void swap(int *xp,int *yp) { int tmp; tmp=*xp; *xp=*yp; *yp=tmp; } int main() { int a, ; cina ; swap(a, ); cout return 0; } 2、编写主程序,将输⼊字符串反序输出。程序 ⾏结果如下: 输⼊:ABCDEFGHIJK 输出:KJIHGFEDCBA #include #include using namespace std ; int main() { char str[100]; cinstr; int len; len=strlen(str); char *p=str[len-1]; w hile(p=str) { cout*p; p--; } cout return 0; } 3、使⽤指针编写⼀个⽤于对整型序列进⾏排序的函数,排序⽅法使⽤简单选择排序法。 程序的 ⾏结果如下所⽰: 输⼊(第⼀个数是序列的长度) : 6 2 7 2 2 3 1 输出: 1

文档评论(0)

1亿VIP精品文档

相关文档