C语言复习题指针结构体
return 0;
}
答:
a = ?34
b = ?58
a =3+4i
b =5+8i
c =8+12i
5、
#include <stdio.h>
struct date
{
int year;
int month;
int day;
};
void func(struct date *p)
{
p->year = 2000;
scanf("%d", &n);
InputArray(a, n);
SortArray(a, n);
OutputArray(a, n);
return 0;
}
void InputArray(double *p, int n)
{
int k;
for (k = 0; k < n; k ++)
{
scanf("%lg", &p[k]);
double MaxArray(double *p, int n);
double SumArray(double *p, int n);
#include <stdio.h>
void InputArray(double *p, int n);
double MaxArray(double *p, int n);
仔细阅读程序,请先指出错误行号,并改正使它能得出正确的结果。
注意:不要改动main函数,不得增或删行,也不得更改程序的结构!
①#include<stdio.h>
②void fun(int *x,*y)
③{ int t;
④t=x;
⑤x=y;
⑥y=t;
}
intmain( )
{ int a,b;
⑦printf("Enter a,b: ");
D)s1.strcpy(y,”abc”);
9、已知定义“int x=1, *p”,则合法的赋值表达式是A。
A)p=&xB)p = xC)*p=&xD)*p=*x
10、在C语句中,&后跟指针变量名,表示该指针变量的C。
A)值B)别名C)地址D)类型
二、程序填空
1、下面程序的功能是实现数组元素中值的逆序。
4、第6行改为*y=t;
4、第8行改为scanf("%d%d",&a,&b);
5、第10行改为fun(&a,&b);
四、写出程序运行结果
1、仔细阅读下面的程序,假设时间a是07:59:59,时间b是08:10:02,请写出程序的输入和输出结果。
#include <stdio.h>
struct TIME
#include "string.h"
intmain ( )
{
int i,n;
char *s="abcdef123";
n=strlen(s);
for (i=n-1;i>=0;i--)
printf("%c",*(s+i));
return 0;
}
答:321fedcba
3、
#include<stdio.h>
void InputArray(double *p, int n);
void OutputArray(const double *p, int n);
void SortArray(double *p, int n);
#include <stdio.h>
void InputArray(double *p, int n);
double SumArray(double *p, int n);
int main()
{
double a[100];
int n;
printf("n = ? ");
scanf("%d", &n);
InputArray(a, n);
};
void InputComplex(struct COMPLEX *p)
{
scanf("%lg %lg", &p->re, &p->im);
}
void OutputCoord(struct COMPLEX p)
{
printf("%lg%+lgi", p.re, p.im);
}
struct COMPLEX Add(struct COMPLEX p, struct COMPLEX q)
void Fun(int *y);
int main ( )
{
int x = 10;
printf("x = %d\n", x);
Fun(&x);
printf("x = %d\n", x);
return 0;
}
void Fun(int *y)
{
printf("*y = %d\n", *y);
*y = 20;
}
int Sub(struct TIME x, struct TIME y)
{
int t1 = x.hour * 3600 + x.minute * 60 + x.second;
int t2 = y.hour * 3600 + y.minute * 60 + y.second;
return t1 - t2;
}
int main()
{
struct TIME a, b;
intr;
printf("a = ? ");InputTime(&a);
printf("b = ? ");InputTime(&b);
r= Sub(bΒιβλιοθήκη a);printf("a = ");OutputTime(a);putchar('\n');
5、若有定义如下:int i=3,*p=&i;显示i的值的正确语句是B。
A)printf(“%d”,p);
B)printf(“%d”,*p);
C)printf(“%p”,*p);
D)printf(“%p”,p);
6、在定义结构体时,下列叙述正确的是A。
A)系统不会分配空间
B)系统会按成员大小分配空间
p->month = 5;
p->day = 22;
}
int main()
{
struct date d;
d.year = 1999;
d.month = 4;
d.day = 23;
printf("%d,%d,%d\n",d.year, d.month, d.day);
func(&d);
printf("%d,%d,%d\n",d.year, d.month, d.day);
void OutputArray(const double *p, int n);
void SortArray(double *p, int n);
void Swap(double *x, double *y);
int main()
{
double a[100];
int n;
printf("n = ? ");
{
struct COMPLEX r;
r.re = p.re + q.re;r.im = p.im + q.im;
return r;
}
int main()
{
struct COMPLEX a, b, c;
printf("a = ? "); InputComplex(&a);
printf("b = ? "); InputComplex(&b);
}
}
void OutputArray(const double *p, int n)
{
int k;
for (k = 0; k < n; k ++)
{
printf("%lg ", p[k]);
}
putchar('\n');
}
void SortArray(double *p, int n)
{
int i, j;
{
int hour, minute, second;
};
void InputTime(struct TIME *p)
{
scanf("%d:%d:%d", &p->hour, &p->minute, &p->second);
}
void OutputTime(struct TIMEp)
{
printf("%02d:%02d:%02d",p.hour,p.minute,p.second);
printf("*y = %d\n", *y);
}
答:
x=10
*Y=10
*Y=20
X=20
4、仔细阅读下面的程序,当复数a为3+4i, b为5+8i时,请写出程序的输入和输出结果。
#include <stdio.h>
#include <math.h>