写出程序的运行结果,再进行运行比较

来源:互联网 发布:ip反查域名网站 编辑:程序博客网 时间:2024/06/12 21:11

作者:夏晓林

时间:2016.11

问题及代码4:

#include <stdio.h>int main(){    int *p1,*p2,*p;    int a=5,b=8;    p1=&a;    p2=&b;    if(a<b)    {        p=p1;        p1=p2;        p2=p;    }    printf("%d,%d\n",*p1,*p2);    printf("%d,%d\n",a,b);    return 0;}

运行结果:


问题及代码5:

#include<stdio.h>void fun(int x,int y,int *z){    x*=x;    y*=y;    *z=x+y;}int main(){    int a=5,b=2,c=31;    fun(a,b,&c);    printf("%d %d %d\n",a,b,c);    return 0;}

运行结果:


问题及代码6:

#include<stdio.h>int a, b;void fun(int *p1, int *p2){    *p1=&a;*p2=&b;    *p1=100;*p2=200;}int main(){    int a=5, b=7;    fun(&a, &b);    printf("%d %d\n", a, b);    return 0;}

运行结果:


问题及代码7.

#include<stdio.h>#include<malloc.h>int *fun(int x,int y,int *cp){    *cp=x*x+y*y;    return cp;}int main(){    int a=4,b=3,*c,*d;    c=(int*)malloc(sizeof(int));    d=fun(a,b,c);    printf("%d %d\n",*c,*d);    return 0;}

运行结果:


0 0
原创粉丝点击