-
习
题
1
、用变量
a
给出下面的
定义
a)
一个整型数
b)
一个指向整型数的指针
c)
一个指向指针的的指针,它指向的指针是指向一个整型数
d)
一个有
10
个整型数的数组
e)
一个有
10
个指针的数组,该指针是指向一个整型数的。<
/p>
f)
一个指向有
10
个整型数数组的指针
g)
一个指向函数的指针,该函数有一个整型参数并返回一个整型数
h)
一个有
10
个指针的数组,
该指针指向一个函数,
该函数有一个整型参
数并返回一个
整型数
2
、在某工程中,要求设置一绝对地址为
0x67a9
的整型变量的值为
0xaa66
。假设编译器是
一个纯粹的
ANSI
编译器。
3
、下面的代码输出是什么,为什么?
void foo(void)
{
unsigned int a = 6;
int b =
-20;
(a+b > 6) ? puts(
}
4
、怎么样编写死循环呢?请写出最佳的方式。
5
、在
C
语言
中,关键字
static
的作用是什么?
6
、关键字
const
有什么含意?至少说明两种用途。
7
、请填写
bool
,
float
,
指针变量
与“零值”比较的
if
语句。
8
、以下为
Windows NT
p>
下的
32
位
C++
程序,请计算
sizeof
的值
(
1
)
char
str[] =
“Hello”
char
*p = str
int
n = 10;
请计算:
sizeof (str ) =
sizeof ( p ) =
sizeof ( n ) =
(
2
)
void Func ( char str[100])
{
cout << sizeof( str )
// =
}
(
3
)
void *p = malloc( 100 );
请计算:
sizeof ( p )
=
9
、头文件中的
ifndef/define/endif
干什么用?
10
、
#include
和
#include
“filename.h”
有什么区别?
11
< br>、下面是有关内存的思考题,请问运行
Test
函数会有
什么样的结果?
(
1
)
void GetMemory(char *p)
{
p = (char *)malloc(100);
}
void Test(void)
{
char *str = NULL;
GetMemory(str);
strcpy(str,
printf(str);
}
(
2
)<
/p>
char *GetMemory(void)
{
char p[] =
return p;
}
void
Test(void)
{
char *str =
NULL;
str = GetMemory();
printf(str);
}
(<
/p>
3
)
void
GetMemory2(char **p, int num)
{
*p = (char *)malloc(num);
}
void Test(void)
{
char *str = NULL;
GetMemory(&str, 100);
strcpy(str,
printf(str);
} <
/p>
(
4
)
void
Test(void)
{
char *str =
(char *) malloc(100);
strcpy(str,
“
hell
o
”
);
free(str);
if(str != NULL)
{
strcpy(str,
“
world
”
);
printf(str);
}
}
12
、已知
strcpy
函数的原型是:
char *strcpy(char *strDest, const char
*strSrc);
其中
strD
est
是目的字符串,
strSrc
是
源字符串。
不调用
C++/C
的字符串库函数,请编写函数
strcpy
13
、请说明下列第
2
、
3
行语句的含义。
const int number = 1;
const
int * const pNumber = & number;
const int & number1 = number;
14
、写一个“标准”宏
MIN
,这个宏输入两个参数并返回较小的一个。
< br>15
、
嵌入式系统总是要用户对变量或寄存器进行位操作
。
给定一个整型变量
a
,
写两段代码,
第一个设置
a
的
bit 3
,第二个清除
a
的
bit
3
。在以上两个操作中,要保持其它位不变。
16
、给出下列程序运行后的输出结果
1)#include
void
main()
{
char
a[]=
int i1=0, i2=0,
i=0;
while(a[i])
{
if(a[i]=='a') i1++;
if(a[i]=='b') i2++;
i++;
}
cout<
}
2)
#include
void LE(int *a, int
*b)
{
int x=*a;
*a=*b;
*b=x;
cout<<*a<<'
'<<*b<
}
void
main()
{
int x=10, y=25;
LE(&x,&y);
cout<
}
17
、
编写能统计某个子串在一个字符串中出现次数的函数,
该函数能利用引用的
方式将统计
结果带回给主调函数,请编写函数,利用
main<
/p>
函数调用并测试它。
18
、使用函数重载,用递归法对整型数组与字符串进行倒置。
19
、请简答下列一些问题:
1
)
在
p>
C++
程序中,使用基本输入输出流需要包含的头文件是
_________
。
2
)
假定有如下定义:
int
x;
,若要将整型变量
y
定义为变量
x
的引用,则应使用的定
义
语句是
_________
。
3
)
在文件
中定义变量
int
x
,
如果在文件
中使用该变量,
那么在
文件
___
①
p>
___
开始处应加上语句
___
②
___
。
4
)
以
p>
/*
开始,
*/
结
束,在
/*
和
*/
之间的部分即为
_________
。
20
、假定输入字符串为
abe
defg
。写出下列程序的运行结果。
#include
void
main()
{
-
-
-
-
-
-
-
-
-
上一篇:C++考试题答案
下一篇:写心情不好的英语句子