12.23更新5道编程!基本都是关于指针的知识点

1.

给出下述程序的执行结果    1, -2             

#include <stdio.h>

main()

{

 int x=2,y=1;

 while(x--!=-1)

 {

  do{

   y*=x;

   y++;

  }while(x--);

 }

 printf("%d, %d\n",y,x);

}

 

2.

下面程序的运行结果是      computerlanguage     .

#include <stdio.h>

char *strc(char *str1, char *str2);

main()

{

char s1[80] = "computer", s2[] = "language", *pt;

pt = strc(s1, s2);

printf("%s\n", pt);

}

char *strc(char *str1, char *str2)

{

char *p;

for (p = str1; *p != ’\0’; p++);

do {

*p++ = *str2++;

} while(*str2 != ’\0’);

*p = ’\0’;

return (str1);

}

 

3.

写出程序的运行结果       1, 2, 3, 3, 5, 4     

#include <stdio.h>

main()

{

 int a[] = {1,2,3,4,5,6};

 int *p;

 p=a;

 printf("%d, ",*p);

 printf("%d, ",*(++p));

 printf("%d, ",*++p);

 printf("%d, ",*(p--));

 p+=3;

 printf("%d, %d\n",*p, *(a+3));

}

 

 

4.

 *pp1=14,*pp2=10 a=14,b=10                

#include <stdio.h>

swap(int *p1, int *p2) {

 int n;

 n=*p1;

 *p1=*p2;

 *p2=n;

}

main() {

 int a=10,b=14,*pp1,*pp2;

 pp1=&a;pp2=&b;

 swap(pp1,pp2);

 printf("*pp1=%d,*pp2=%d\n",*pp1,*pp2);

 printf("a=%d,b=%d\n",a,b);

}     

 

 

5. 

下面的程序实现从10个数中找成最大值和最小值      p q<10 max<=*q min>*q     

int max, min;

find_max_min( int *p, int n )

{

 int *q;

 max = min = *p;

 for(q=________;______;q++)

 {

  if(_____)

   max = *q;

  else

   if(____)

   min=*q;

 }

}

main()

{

 int i, num[10];

 printf("intput 10 numbers:\n");

 for(i=0;i<10;i++)

 scanf("%d",%num[i]);

 find_max_min(num,10);

 printf("max=%d;min=%d\n",max, min);

}

 

  • 15
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值