1、
#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);
}
最后会显示语法错误,编译不成功
2、
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);
}
冒号相当于分配几位空间,分配成员a,4位空间,b,5位空间,c,7位空间。一共是16位,正好两个字节。
test 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
test.a 0 0 1 0
test.b 0 0 0 1 1
test.c 0 0 0 0 0 0 0
对于i=*((short*)&test);取地址&test开始两个字符(short占两个字节)的内容转化为short型数据,即为0x0032,再转化为int型为0x00000032,即50.
3、
vector是顺序存储的,只有在尾部插入才不会导致迭代器失效,在头部插入或者中间插入都会导致插入的部位以及其后的所有迭代器都失效;
map是映射,key和value是一一对应的,在内存中是零散存在的,迭代器通过key找到value,无论怎么插入都不会让迭代器失效,当然删除只会
使得被删除元素的迭代器失效
4、
内联函数在运行时是将该函数的目标代码插入每个调用该函数的地方 x
应该是编译时,而不是运行时。
5、
运行下面这段C语言程序之后,输出在屏幕上的结果是:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
void
foobar(
int
a,
int
*b,
int
**c)
{
int
*p = &a;
*p = 101;
*c = b;
b = p;
}
int
main()
{
int
a = 1;
int
b = 2;
int
c = 3;
int
*p = &c;
foobar(a, &b, &p);
printf
(
"a=%d, b=%d, c=%d, *p=%d\n"
, a, b, c, *p);
return
(0);
}
|
- a=1, b=2, c=3, *p=2
- a=101, b=2, c=3, *p=2
- a=101, b=101, c=2, *p=3
- a=1, b=101, c=2, *p=3
![](https://i-blog.csdnimg.cn/blog_migrate/bc51fd6ff50041ff1b06385d46d2d005.png)