3.08C语言考试
(2012-03-11 18:23:43)
标签:
c语言考试 |
分类: CPP |
说明:有些题是有争议的。
1,以下合法的变量或者宏的名称有
2,下面选项中等于数字077的有
3,已知存在一个数组int
4,以下正确的写法是?
5,已知整数变量a, b则能正确表达条件“两者不等”的是?
6,以下正确的声明语句有?
7,已知int *a[10]; int b[3][10],则sizeof(a), sizeof(b[2])的结果是?
8,以下哪个指针的更适合指向一个二维数组char a[3][10]?
9,以下说法正确的是?
填空题
1,C的每条语句后面必须加上
2,int a = 3; int b = a++;
b的值是
3,char a[20] = “hello
world”;则*(a+3)的值是
4,已知有如下定义:
5,已知有如下定义:
6,已知有如下定义:
7,C语言中如何防止头文件被多次包含?
#ifndef
头文件名
#define 头文件名
#endif
8,已知有如下定义:
9,编写一个带参数的宏,实现返回两个数中较小的一个
#define MIN(a, b)
#define MIN(a, b, c)
10,以下函数的运行会有什么后果:
运行结果:死循环 ,unsigned char类型的i最大值是255。
11,已知有如下定义:
12,下面程序的结果是:
13,int (*s[10])(int)表示的是这是一个有10个元素的数组,元素为指针,指针指向一个函数,函数的参数类型为int,返回值类型也为int。
14,已知一个数组,数组名是tabel,定义一个宏,来求解元素的个数
15,已知char str[] = “hello world”;char *p = str则
16,enum color{red, blue, black = 3,
yellow}则如果a = red;b =
yellow则a=
17,定义两个宏,分别实现对某个整型变量的某一位清零或者置一。
18,void func ( char str[100] )
19,已知char *p = (char
*)malloc(100);则sizeof(p)=
三.找错题
1.以下程序会将输入的字符串倒序,请查找下面代码的错误,并指明。
#include<string.h>
int reverse_string(const char * src)
{
int len=strlen(src);
dest=(char*)malloc(len);
char *d=dest;
char *s=src[len];
while(len--!=0)
}
修改后:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int reverse_string(const char * src)
{
}
2.对于下面的函数,要求打印出”hello”,
子程序完全正确的是
一定能打印出”hello”的是
有错误的是
char *GetHellostr(void);
int main(void)
{
}
(1)
char *GetHellostr(void)
{
}
(2)
char *GetHellostr(void)
{
}
//a在栈里,函数调用结束后,a就释放了。
(3)
char *GetHellostr(void)
{
}
(4)
char *GetHellostr(void)
{
}//没有释放ps。
四.问答题
1.堆和栈的区别?
2.比较带参数的宏和函数的优缺点?
3.写出gcc编译程序的主要步骤(写出编译语句即可)。
五.编程题
1.实现一个mystrcpy函数,作用如同标准库函数strcpy
1.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char * mystrcpy(char * s1, const char * s2)
{
}
int main(void)
{
}
2.实现一个函数在一个整形数组里面找出最大的那个数,函数原型如下所示:
2.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int get_max(int a[], int n)
{
}
int main(void)
{
}
3.不使用中间变量交换两个整形变量的值,写出两种方式。
#define SWAP1(a, b)
#define SWAP2(a, b)
4.函数atoi用于将类似于”123”这样的由阿拉伯数字构成的字符字符串转化成整数123,请编程实现。
4.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int myatoi(const char * v)
{
}
int main(int c, char **v)
{
}
5.使用任意方法实现将数组int a[5]排序。
冒泡排序:
5.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
}
6.使用任意方法实现文件复制程序。
6.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/uio.h>
#define BUF 512
int main(int c, char ** v)
{
}
7, 使用任意方法实现文件剪切程序。
ln -s test test1创建软链接(快捷方式)
ln test test1创建硬链接
ls -l test查看test信息
link()函数创建硬链接
unlink()函数删除硬链接
删除文件就是删除硬链接
7.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
}
8.编写一个程序将输入字符串中的大写字母转化为小写字母,并返回大写字母的个数。函数原型如下:
int func(char * p)参数src为输入的字符串,函数的返回值为字符串中大写字母的个数。
8.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int func(char * p)
{
}
int main(int c, char **v)
{
}
9.编写一个函数,用来在一个给定的整形数组里面找出第2大的数。函数原型如下
int func(int a[], int n)
参数a为数组的地址,n为数组的个数。
函数返回值就是要找的数。
9.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int func(int a[], int n)
{
}
int main(void)
{
}
10.用递归方法判断一个数组是否为递增数组(使用递归时充分考虑递归终止条件,以及函数调用思想),函数原型如下;
int func(int a[], int n)
参数a为数组的地址,n为数组的个数。
函数的返回值如果为0则该数组为递增数组,为1则是递减数组。
10.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int func(int * a, int n)
{
}
int main(void)
{
}