C语言指针和函数填空题

以下是一些C语言指针和函数的填空题,每个题目都提供了一个代码片段,你需要填空完成代码,并理解其功能。

1. (填空题, 5分) 以下程序运行后的输出结果是'', ''。

#include <stdio.h>
void swap(int *x,int *y)
{
    int t;
    { t=*x; *x=*y; *y=t;}
    printf("%d %d\n",*x,*y); 
}
void main()
{
    int a[]={2,3};
    swap(&a[0],&a[1]);
    printf("%d %d\n", a[0],a[1]); 
}

第1空: 3 第2空: 2

2. (填空题, 5分) 下列程序输出后的结果是'', ''。

#include <stdio.h>

void swap(int x[])
{
    int t;
    { t=x[0]; x[0]=x[1]; x[1]=t;}
    printf("%d  %d\n",x[0],x[1]); 

}

void main()
{
    int a[]={2,3};

    swap(a);
    printf("%d  %d\n", a[0],a[1]);

}

第1空: 3 第2空: 2

3. (填空题, 5分) 下列程序输出后的结果是'', ''。

#include <stdio.h>

void swap(int *x,int *y)
{
    int *t;
    { t=x; x=y; y=t;}
    printf("%d  %d\n",*x,*y); 

}

void main()
{
    int a[]={2,3};

    swap(&a[0],&a[1]);
    printf("%d  %d\n", a[0],a[1]); 

}

第1空: 3 第2空: 2

4. (填空题, 5分) 以下程序输出的结果是'________', '__________'。

#include <stdio.h>

void main()

{
    char *p="abcdefgh" , c[10]="XYZ";

    p+=3 ;

    puts(strcat(c,p));

    printf("%d\n",strlen(c));

}

第1空: XYZdefgh 第2空: 10

5. (填空题, 5分) 下列程序输出的结果为'________'。

#include  <stdio.h>

void fun(int *pa)

{
  printf("%d\n",pa[5]); 

}

int main()

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

    fun(&a[2]);

    return 0;

}

第1空: 5

6. (填空题, 5分) 以下程序的输出结果是'', '', '_________'。

 #include <stdio.h>

 void main()

{int *p1,*p2,*p;

 int a=3,b=4;

 p1=&a;p2=&b;

 printf("%d,%d\n",*p1,*p2);

 p=p1;p1=p2;p2=p;

 printf("%d,%d\n",*p1,*p2);

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

}

第1空: 3, 4 第2空: 4, 3 第3空: 4, 3

7. (填空题, 5分) 以下程序运行后的输出结果是'', ''。

#include <stdio.h>
void swap(int a,int *b)
{
    int c;
    c=a; a=*b; *b=c;
    printf("%d %d",a,*b);
}
void main()
{
    int a=3,b=2;
    swap(a,&b);
    printf("%d %d", a,b);
}

第1空: 2, 3 第2空: 3, 2

8. (填空题, 5分) 程序运行时,输出结果为'________', '_, ''。

int main()

{
    int a=1,*p=&a;

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

    a=2;

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

    *p=3;

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

    return 0;

}

第1空: 1, 1 第2空: 2, 1 第3空: 3, 3

9. (填空题, 5分) 下面程序是一个二级指针引用字符串的例子,程序输出结果'________'。

int main()

{
    char  * name[ ]= {"abc","def","ghi"};

    char **p;

    p=name+2;

    printf("%s\n",*p);

    return 0;

}

第1空: ghi

10. (填空题, 5分) 函数调用只能调用指定的一个函数,用函数的指针变量可以调用一类函数。下面程序定义了一个函数指针,请填空( )。

#include <stdio.h>

int min(int m,int n)           

{  return (m<n? m:n);}

void main()

{
  int (*p)(int,int); // 函数指针定义

    int a,b,c;

    p= __ _;      

    scanf("%d%d",&a,&b);

    c= ______;                  

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

}

第1空: min 第2空: p(a, b)

C语言指针与函数填空题 - 练习你的编程技能

原文地址: https://www.cveoy.top/t/topic/orkz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录