1
2
3
4
|
class
packet{
int
size;
void
data[
0
];
}
|
1
|
time_t t;
|
关于“深拷贝”,下列说法正确的是:
1
|
"My salary was increased by 15%!"
|
1
2
3
4
5
6
7
8
9
10
11
12
|
int
func(
int
a)
{
int
b;
switch
(a)
{
case
1
: b =
30
;
case
2
: b =
20
;
case
3
: b =
16
;
default
: b =
0
;
}
return
b;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
|
int
func(
int
a)
{
int
b;
switch
(a)
{
case
1
: b =
30
;
case
2
: b =
20
;
case
3
: b =
16
;
}
return
b;
}
|
若有以下程序
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include<stdio.h>
main()
{
int
s=
0
,n;
for
(n=
0
; n<
4
; n++)
{
switch
(n)
{
default
:s+=
4
;
case1:s+=
1
;
case2:s+=
2
;
case3:s+=
3
;
}
}
printf (
"%d\n"
,s);
}
|
则程序的输出结果是?
24
1
2
3
|
fun(
char
* p) {
return
p;
}
|
若有以下程序
1
2
3
4
5
6
7
8
9
|
#include <stdio. h>
main( )
{
int
a =
0
,b =
0
,c =
0
,d;
c = (a + = b,,b + = a); / * 第
4
行 * /
d = c; / * 第
5
行 * /
; / * 第
6
行 * /
;printf(
"%d,%d,%d\n"
,a,b,c);/ * 第
7
行 * /
}
|
编译时出现错误,你认为出错的是
第4行逗号表达式中间的第二个表达式为空,是不合法的,可以去掉写成a + = b,b + = a,也可以在里面补一个表达式,如a + = b,a,b + = a。所以选择A选项。
1
2
|
void
test(
int
a){}
void
test(
float
a){}
|
1
2
|
int
a=
25
;
print_value(&a);
|
1
2
3
4
|
void
print_value(
int
* x)
{
printf(“%x\n”,++*x);
}
|
1
2
3
4
|
int
a1=x+y-z;
int
b1=x*y/z;
int
a2=x-z+y;
int
b2=x/z*y;
int
c1=x<<y>>z;
int
d1=x&y|z;
int
c2=x>>z<<y;
int
d2=x|z&y;
|
1
2
3
4
5
|
void
swap_int(
int
*a,
int
*b){
*a=*a+*b;
*b=*a-*b;
*a=*a-*b;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#include <stdio.h>
#define SUB(x,y) x-y
#define ACCESS_BEFORE(element,offset,value) *SUB(&element, offset) = value
int
main() {
int
array[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int
i;
ACCESS_BEFORE(array[5], 4, 6);
printf
(
"array: "
);
for
(i = 0; i < 10; ++i) {
printf
(
"%d"
, array[i]);
}
printf
(
"\n"
);
return
(0);
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#include "iostream"
#include "vector"
using namespace std;
int main(void)
{
vector<int>array;
array.push_back(100);
array.push_back(300);
array.push_back(300);
array.push_back(500);
vector<int>::iterator itor;
for
(itor=array.begin();itor!=array.end();itor++)
{
if
(*itor==300)
{
itor = array.erase(itor);
}
}
for
(itor=array.begin();itor!=array.end();itor++)
{
cout<<*itor<<
" "
;
}
return
0;
}
|
1
2
3
4
|
const
int
i =
0
;
int
*j = (
int
*) &i;
*j =
1
;
printf(
"%d,%d"
, i, *j)
|
|
const
修饰符表示i为常量,值不可改变,但是通过指针可以改变内存中i所在地址中的值,所以输出*j的值变为1。但是通过编译器优化,i的值不再是每次都在内存中读取,而是见到i编译器就可自动赋值为最初的值0,所以输出i的值时为0,答案为A 0,1。
|
1
2
|
int
*p1 =
new
int
[
10
]; // 10个未初始化int new student
int
*p2 =
new
int
[
10
]();// 10个值初始化为0的int new Student()
|
1
2
3
|
signed
char
a=0xe0;
unsigned
int
b=a;
unsigned
char
c=a;
|
1
2
3
4
5
6
|
struct st_task
{
uint16_t id;
uint32_t value;
uint64_t timestamp;
};
|
1
2
3
4
5
6
7
|
void
fool()
{
st_task task = {};
uint64_t a =
0x00010001
;
memcpy(&task, &a, sizeof(uint64_t));
printf(
"%11u,%11u,%11u"
, task.id, task.value, task.timestamp);
}
|
1
2
3
4
|
union
X{
int
x;
char
y[4];
};
|
1
|
写出下列程序在X86上的运行结果
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
struct
mybitfields
{
unsigned
short
a : 4;
unsigned
short
b : 5;
unsigned
short
c : 7;
} test
void
main(
void
)
{
int
i;
test.a = 2;
test.b = 3;
test.c = 0;
i = *((
short
*)&test);
printf
(
"%d\n"
, i);
}
|
1
2
3
4
5
6
7
8
9
10
11
|
union Test
{
char
a[
4
];
short
b;
};
Test test;
test.a[
0
]=
256
;
test.a[
1
]=
255
;
test.a[
2
]=
254
;
test.a[
3
]=
253
;
printf(
"%d\n"
,test.b);
|
1
2
3
4
5
|
char
array[
12
] = {
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
};
short
*pshort = (
short
*)array;
int
*pint = (
int
*)array;
int64 *pint64 = (int64 *)array;
printf(
"0x%x , 0x%x , 0x%llx , 0x%llx"
, *pshort , *(pshort+
2
) , *pint64 , *(pint+
2
));
|
1
2
3
4
|
unsigned
long
val = 0;
char
a = 0x48;
char
b = 0x52;
val = b << 8 | a;
|
1
2
3
4
5
6
7
8
|
int
main(
void
)
{
char
num;
for
(num =
0
; num <
255
; )
num += num;
printf(
"%d\n"
,num);
return
0
;
}
|
1
2
3
4
5
6
7
|
#define MAX
255
int
main()
{
unsigned
char
A[MAX], i;
for
(i =
0
; i <= MAX; i++)
A[i] = i;
}
|
1
2
3
4
5
6
7
8
9
10
11
|
#include<stdio.h>
int
main()
{
uint32_t a =
100
;
while
(a >
0
)
{
--a;
}
printf(
"%d"
, a);
return
0
;
}
|
#include "stdio.h" int func(int x, int y) { return (x + y); } int main() { int a = 1, b = 2, c = 3, d = 4, e = 5; printf(" % d\n", func((a + b, b + c, c + a), (d, e))); return 0; }
1
2
3
4
5
6
7
8
9
|
int i, n = 0;
float x = 1, y1 = 2.1 / 1.9, y2 = 1.9 / 2.1;
for
( i = 1; i < 22; i++ )
x = x * y1;
while
( x != 1.0 )
{
x = x * y2; n++;
}
printf( “ %d / n ”, n );
|
1
2
3
4
5
6
7
8
9
|
1
.
unsigned
short
i,j;
for
(i=
0
, j=
2
; i!=j; i+=
5
, j+=
7
)
{}
2
.
unsigned
short
i,j;
for
(i=
3
,j=
7
;i!=j;i+=
3
,j+=
7
)
{}
|
1
2
3
4
5
6
|
int
add(
int
*x,
int
*y,
int
*z){
*x += *x;
*y += *x;
*z += *y;
return
*z;
}
|
1
2
3
4
5
6
7
|
enum
string{
x1,
x2,
x3=
10
,
x4,
x5,
} x;
|
1
2
3
4
5
6
|
main()
{
char a=’1’,b=’2’;
printf(“%c,”,b++);
printf(“%d\n”,b-a);
}
|
1
2
3
4
|
int
main(
void
) {
http:
//www.taobao.com
cout <<
"welcome to taobao"
<< endl;
}
|
a.成员函数被重载的特征:
(1)相同的范围(在同一个类中);
(2)函数名字相同;
(3)参数不同;
(4)virtual 关键字可有可无。
b.覆盖是指派生类函数覆盖基类函数,特征是:
(1)不同的范围(分别位于派生类与基类);
(2)函数名字相同;
(3)参数相同;
(4)基类函数必须有virtual 关键字。
c.“隐藏”是指派生类的函数屏蔽了与其同名的基类函数,规则如下:
(1)如果派生类的函数与基类的函数同名,但是参数不同。此时,不论有无virtual关键字,基类的函数将被隐藏(注意别与重载混淆)。
(2)如果派生类的函数与基类的函数同名,并且参数也相同,但是基类函数没有virtual 关键字。此时,基类的函数被隐藏(注意别与覆盖混淆)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
class Test
{
public:
____ int a;
____ int b;
public:
Test::Test(int _a , int _b) : a( _a )
{
b = _b;
}
};
int Test::b;
int main(void)
{
Test t1(0 , 0) , t2(1 , 1);
t1.b = 10;
t2.b = 20;
printf(
"%u %u %u %u"
,t1.a , t1.b , t2.a , t2.b);
return
0;
}
|
1
2
|
typedef
char
T[
10
] ;
T * a ;
|
以下代码的输出结果是?
1
2
3
4
5
|