达内C++班Core C部分测试题

匿名网友 匿名网友 发布于: 2015-08-30 00:00:00
阅读 153 收藏 0 点赞 0 评论 0

达内C++班Core C部分测试题

姓名:            成绩:

1. 结构体与联合体有何区别?(5分)

 

 

2. h头文件中的ifndef/define/endif 的作用?(5分)

 

3. i nclude<file.h> i nclude “file.h”的区别?(5分)

 

 

 

4. 以下为Windows NT下的32位C++程序,请计算sizeof的值(10分)

char  str[] = “Hello” ;

char   *p = str ;

int     n = 10;

请计算sizeof (str ) =     (2分)

sizeof ( p ) =      (2分)

sizeof ( n ) =      (2分)

void Func ( char str[100])

{

请计算

sizeof( str ) =        (2分)

}

void *p = malloc( 100 );

请计算

sizeof ( p ) =        (2分)

5. 分析以下程序并回答问题(5分)

void GetMemory(char *p)

{

p = (char *)malloc(100);

}

void Test(void)

{

char *str = NULL;

GetMemory(str);

 

strcpy(str, “hello world”);

printf(str);

}

请问运行Test函数会有什么样的结果?

 

 

6. 请分析以下程序输出结果:(5分)

#include<stdio.h>
main()
{
int a,b,c,d;
a=10;
b=a++;
c=++a;
d=10*a++;

printf(“b,c,d:%d,%d,%d”,b,c,d);
return 0;
}

 

7.请写出程序出出结果(5分)

main()
{
int a[5]={1,2,3,4,5};
int *ptr=(int *)(&a+1);

printf(“%d,%d”,*(a+1),*(ptr-1));
}

8.用至少两种方法将一个整数转化为其数字字符串(10分)

 

9.用程序描述冒泡排序算法,并简要叙述其原理(10分)

 

10.自己实现C风格字符串操作的三个函数int strlen(const char* s),

char* strcpy(char* dest,const char* str),

char* strcat(char* dest,const char* src);(20分)

 

 

11.简述C语言内存三大分配函数的用法?(提醒:calloc,malloc,realloc)

(10分)

12.新建文件file2.txt,将已经存在的文件file1.txt中的内容写入file2.txt当中(10分)

 

评论列表
文章目录