深信服科技2019年校園招聘研發試題
阿新 • • 發佈:2019-01-23
1、
#include <stdio.h>
int main()
{
char *str1 = "abcd\n";
char str2[10] = "abcd\n";
char str3[][10] = {"abcd\n",""};
char *str4[] = {"abcd\n",""};
printf("%d\n%d\n%d\n%d\n", sizeof(str1),sizeof(str2),sizeof(str3),sizeof(str4));
}
輸出
8
10
20
16
str1是一個指標,64位系統裡指標大小為8個位元組,32位為4個位元組
str2為一個數組,sizeof計算陣列大小,跟字串無關
str3為一個二維陣列,同樣是計算陣列大小
str4為一個指標陣列,也就是裡面都是指標,2個指標也就是16個位元組
2、
7條線可以把平面分成幾個部分
29個部分,(n * n + n + 2) / 2
3、
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
union my
{
int intVal;
char charVal[4];
};
int main()
{
my test;
test.intVal = 0x12345678;
test.charVal[1] = 0x22;
printf("%x", test.intVal);
return 0;
}
輸出
12342278,不是12225678
12345678在記憶體中是從高位到低位
a[0]: 78
a[1]: 56
a[2]: 34
a[3]: 12
因此charVal[1]該的是56,所以就有上面的結果
例如
以十進位制為例, 10^0肯定是最低位——個位 10^1高一點點——十位 10^2更高一點——百位
我們書寫從高位到低位,百十個,記憶體是反向的,個十百
4、
#include <stdio.h>
int main()
{
char c[100] = "abc\0def";
printf("%c", c[4]);
}
輸出d
\0是一個字元,也就是結束標記
printf(“%s”, c);
會輸出abc