Sorry.必须做一些面试题。不然感觉自己心里很没有底。
这里记录一下知识点:
1.Say something about 析构函数和vitual函数;
2.#define SQR(X) X*X和int x=10,y=10,e=3; e*=x+y; 你懂的。
3.const 符号
4.strcpy,strncpy,memcpy
可能会涉及自己实现strcpy函数,strcpy很容易数组越界。
5.static三大作用
1.隐藏;
2.保存在静态存储区,导致函数变为不可重入函数;
3.初始化为0;
6.if(n==1)和if(1==n)哪个更好?为么呢?
有两个比较有意思的题目:
如何区分16位操作系统和32位操作系统?若不使用sizeof呢?
这里必须说一下,何谓补码? 1.正数的补码和原码相同; 2.负数的补码等于其源码的符号位不变,数值部分的各位取反,然后整个数加1。 计算机中存放的为补码。
16位系统下:
int i=65535;
cout<<i; //i=-1;
i=65536;
cout<<i; //i=0;
32位系统下:
int i=65535;
cout<<i; //i=65535;
i=65536;
cout<<i; //i=65536;
如何判断计算机的存储字节顺序?
#include<stdio.h>
void byteorder();
int main() {
byteorder();
return 0;
}
void byteorder() {
union {
short s;
char c[sizeof(short)];
} tt;
tt.s = 0x0102;
printf("%d\n",tt.c[0]);
printf("%d\n",tt.c[1]);
}
源码地址:https://github.com/Tinyxml/MyCode/blob/master/UNP/C1/byteorder.c
需要注意的:
union V{
struct X{
unsigned char s1:2;
unsigned char s2:3;
unsigned char s3:3;
}x;
char c;
}v;
v.c=100;
printf("%d\n",v.x.s3);
以上代码输出?
100转化为2进制为1100100
额。。结果为3.
多次碰到,但是仍然纠结的题目,如下:
指出下列程序错误,并改正!
void GetMemory(char *p) {
p = (char *) malloc(100);
}
void Test(void) {
char *str=NULL;
GetMemory(str);
strcpy(str,"hello world");
printf(str);
}